Author: khmarbaise Date: Sat Dec 19 21:47:20 2015 New Revision: 1720976 URL: http://svn.apache.org/viewvc?rev=1720976&view=rev Log: [MJAR-198] jar:jar without classifier replaces default jar The maven-jar-plugin now will fail if you try to replace the original artifact in case of a second execution without defining a classifier. Improved documentation about the classifier.
Added: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/invoker.properties maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml (with props) maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java (with props) Modified: maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/JarMojo.java Added: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/invoker.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/invoker.properties?rev=1720976&view=auto ============================================================================== --- maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/invoker.properties (added) +++ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/invoker.properties Sat Dec 19 21:47:20 2015 @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = clean package +invoker.buildResult = failure Added: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml?rev=1720976&view=auto ============================================================================== --- maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml (added) +++ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml Sat Dec 19 21:47:20 2015 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>0</groupId> + <artifactId>0</artifactId> + <version>1.0-SNAPSHOT</version> + <description>MJAR-198 integration test</description> + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>@project.version@</version> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>executable</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>A</mainClass> + </manifest> + </archive> + <finalName>executable</finalName> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/pom.xml ------------------------------------------------------------------------------ svn:executable = * Added: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java?rev=1720976&view=auto ============================================================================== --- maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java (added) +++ maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java Sat Dec 19 21:47:20 2015 @@ -0,0 +1,5 @@ +public class A { + public static void main(String[] args) { + + } +} Propchange: maven/plugins/trunk/maven-jar-plugin/src/it/MJAR-198/src/main/java/A.java ------------------------------------------------------------------------------ svn:executable = * Modified: maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java?rev=1720976&r1=1720975&r2=1720976&view=diff ============================================================================== --- maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java (original) +++ maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java Sat Dec 19 21:47:20 2015 @@ -254,11 +254,28 @@ public abstract class AbstractJarMojo } else { + if ( projectHasAlreadySetAnArtifact() ) + { + throw new MojoExecutionException( "You have to use a classifier " + + "to attach supplemental artifacts to the project instead of replacing them." ); + } getProject().getArtifact().setFile( jarFile ); } } } + private boolean projectHasAlreadySetAnArtifact() + { + if ( getProject().getArtifact().getFile() != null ) + { + return getProject().getArtifact().getFile().isFile(); + } + else + { + return false; + } + } + /** * @return true in case where the classifier is not {@code null} and contains something else than white spaces. */ Modified: maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/JarMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/JarMojo.java?rev=1720976&r1=1720975&r2=1720976&view=diff ============================================================================== --- maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/JarMojo.java (original) +++ maven/plugins/trunk/maven-jar-plugin/src/main/java/org/apache/maven/plugins/jar/JarMojo.java Sat Dec 19 21:47:20 2015 @@ -44,9 +44,10 @@ public class JarMojo private File classesDirectory; /** - * Classifier to add to the artifact generated. If given, the artifact will be attached. - * If this is not given,it will merely be written to the output directory - * according to the finalName. + * Classifier to add to the artifact generated. If given, the artifact will be attached + * as a supplemental artifact. + * If not given this will create the main artifact which is the default behavior. + * If you try to do that a second time without using a classifier the build will fail. */ @Parameter( property = "maven.jar.classifier" ) private String classifier;