Use the jar-no-fork and test-jar-no-fork goals of the maven-source-plugin - these won’t fork the build (which is what is causing initialize to run multiple times)
On Thursday, 15 January 2015 at 16:24, org.apache.maven.u...@io7m.com wrote: > Hi. > > I have a custom plugin that inserts some extra files into the jars > produced by the jar plugin. Because of the way the plugin works, it > will fail if it tries to make the modifications to a jar file that has > already had the modifications made. For reasons that aren't really > relevant here, modifying the plugin to cope with jars that have been > modified isn't feasible. > > The simplest way to resolve this issue seems to be to have the clean > plugin delete any existing jar file unconditionally (so if the user > doesn't specify "clean" on the command line, the module is cleaned > anyway and the plugin doesn't have to receive an already-edited jar). > > Anyway, the following pom file unconditonally runs the clean plugin > in the initialize phase: > > <?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>com.io7m.example</groupId> > <artifactId>init-test</artifactId> > <version>0.1.0</version> > <packaging>jar</packaging> > > <prerequisites> > <maven>3.0.3</maven> > </prerequisites> > > <properties> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> > </properties> > > <dependencies> > </dependencies> > > <build> > <plugins> > <!-- Clean all artifacts automatically at the start of the build. --> > <plugin> > <artifactId>maven-clean-plugin</artifactId> > <version>2.5</version> > <executions> > <execution> > <id>auto-clean</id> > <phase>initialize</phase> > <goals> > <goal>clean</goal> > </goals> > </execution> > </executions> > </plugin> > > <!-- Create source jar --> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-source-plugin</artifactId> > <version>2.2.1</version> > <executions> > <execution> > <phase>package</phase> > <goals> > <goal>jar</goal> > <goal>test-jar</goal> > </goals> > </execution> > </executions> > </plugin> > </plugins> > </build> > </project> > > This would be fine, except that if you attempt to run the above pom with "mvn > verify", > the maven-source-plugin will cause the maven-clean-plugin to be executed > twice: > > [INFO] Scanning for projects... > [INFO] > [INFO] > ------------------------------------------------------------------------ > [INFO] Building init-test 0.1.0 > [INFO] > ------------------------------------------------------------------------ > [INFO] > [INFO] --- maven-clean-plugin:2.5:clean (auto-clean) @ init-test --- > [INFO] > [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ > init-test --- > [INFO] Using 'UTF-8' encoding to copy filtered resources. > [INFO] skip non existing resourceDirectory > /tmp/sandbox/init-test/src/main/resources > [INFO] > [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ init-test --- > [INFO] No sources to compile > [INFO] > [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ > init-test --- > [INFO] Using 'UTF-8' encoding to copy filtered resources. > [INFO] skip non existing resourceDirectory > /tmp/sandbox/init-test/src/test/resources > [INFO] > [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ > init-test --- > [INFO] No sources to compile > [INFO] > [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ init-test --- > [INFO] No tests to run. > [INFO] > [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ init-test --- > [WARNING] JAR will be empty - no content was marked for inclusion! > [INFO] Building jar: /tmp/sandbox/init-test/target/init-test-0.1.0.jar > [INFO] > [INFO] >>> maven-source-plugin:2.2.1:jar (default) > generate-sources @ > init-test >>> > [INFO] > [INFO] --- maven-clean-plugin:2.5:clean (auto-clean) @ init-test --- > [INFO] Deleting /tmp/sandbox/init-test/target > [INFO] > [INFO] <<< maven-source-plugin:2.2.1:jar (default) < generate-sources @ > init-test <<< > [INFO] > [INFO] --- maven-source-plugin:2.2.1:jar (default) @ init-test --- > [INFO] No sources in project. Archive not created. > [INFO] > [INFO] >>> maven-source-plugin:2.2.1:test-jar (default) > generate-sources @ > init-test >>> > [INFO] > [INFO] --- maven-clean-plugin:2.5:clean (auto-clean) @ init-test --- > [INFO] > [INFO] <<< maven-source-plugin:2.2.1:test-jar (default) < generate-sources @ > init-test <<< > [INFO] > [INFO] --- maven-source-plugin:2.2.1:test-jar (default) @ init-test --- > [INFO] No sources in project. Archive not created. > [INFO] > ------------------------------------------------------------------------ > [INFO] BUILD SUCCESS > [INFO] > ------------------------------------------------------------------------ > [INFO] Total time: 0.925 s > [INFO] Finished at: 2015-01-15T16:05:19+00:00 > [INFO] Final Memory: 10M/228M > [INFO] -------------------------------------------------------- > > Note how auto-clean appears three times! > > In practice, this means that auto-clean runs at the start of the build, and > then > is usually run again at some point after the maven-jar-plugin is executed, > deleting > the jar file. > > Is there any way to stop this from occurring? > > M > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > (mailto:users-unsubscr...@maven.apache.org) > For additional commands, e-mail: users-h...@maven.apache.org > (mailto:users-h...@maven.apache.org) > >