frontend-maven-plugin executed twice - java

frontend-maven-plugin is getting executed twice when i issue the followign command -
mvn clean install package -DenvType=local2
My pom.xml -
<?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.awpl</groupId>
<artifactId>pva-nb-uw-ui</artifactId>
<packaging>war</packaging>
<version>0.2.0</version>
<profiles>
<profile>
<id>local</id>
<activation>
<property>
<name>envType</name>
<value>local</value>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<envType>local</envType>
</properties>
</profile>
<profile>
<id>local2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<envType>local2</envType>
</properties>
</profile>
<profile>
<id>dev</id>
<activation>
<property>
<name>envType</name>
<value>dev</value>
</property>
</activation>
<properties>
<envType>dev</envType>
</properties>
</profile>
<profile>
<id>sit</id>
<activation>
<property>
<name>envType</name>
<value>sit</value>
</property>
</activation>
<properties>
<envType>sit</envType>
</properties>
</profile>
<profile>
<id>uat</id>
<activation>
<property>
<name>envType</name>
<value>uat</value>
</property>
</activation>
<properties>
<envType>uat</envType>
</properties>
</profile>
</profiles>
<build>
<finalName>pva-ui-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<!-- <configuration> <installDirectory>target</installDirectory>
</configuration> -->
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v6.10.0</nodeVersion>
<npmVersion>3.10.10</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>gulp build</id>
<goals>
<goal>gulp</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>optimize --env ${envType}</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The output of the command --
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building artifactname 0.2.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # artifactname ---
[INFO] Deleting D:\Softwares\workspace_eclipse\artifactname\target
[INFO]
[INFO] --- frontend-maven-plugin:1.4:install-node-and-npm (install node and npm) # artifactname ---
[INFO] Node v6.10.0 is already installed.
[INFO] NPM 3.10.10 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.4:npm (npm install) # artifactname ---
[INFO] Running 'npm install' in D:\Softwares\workspace_eclipse\artifactname
[WARNING] npm WARN artifactname#0.2.0 No repository field.
[INFO]
[INFO] --- frontend-maven-plugin:1.4:bower (bower install) # artifactname ---
[INFO] Running 'bower install' in D:\Softwares\workspace_eclipse\artifactname
[INFO]
[INFO] --- frontend-maven-plugin:1.4:gulp (gulp build) # artifactname ---
[INFO] Running 'gulp optimize --env local2' in D:\Softwares\workspace_eclipse\artifactname
[INFO] [10:50:06] Using gulpfile D:\Softwares\workspace_eclipse\artifactname\gulpfile.js
[INFO] [10:50:06] Starting 'lintjs'...
[INFO] [10:50:06] Analyzing JS files
[INFO] [10:50:06] Starting 'linthtml'...
[INFO] [10:50:06] Analyzing HTML files
[INFO] [10:50:06] Starting 'lintcss'...
[INFO] [10:50:06] Analyzing CSS files
[INFO] [10:50:06] Starting 'lintjson'...
[INFO] [10:50:06] Analyzing JSON files
[INFO] [10:50:06] Starting 'clean'...
[INFO] [10:50:06] cleaning ./src/main/webapp/js/,./src/main/webapp/fonts/,./src/main/webapp/resources/,./src/main/webapp/styles/,./src/main/webapp/index.html,./src/main/webapp/rev-manifest.json,./.tmp/
[ERROR] The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information
[INFO] [10:50:07] Finished 'clean' after 1.13 s
[INFO] [10:50:07] Starting 'jsoncopy'...
[INFO] [10:50:07] copying and minifying json resources
[INFO] [10:50:10] Finished 'lintcss' after 3.37 s
[INFO] [10:51:12] Finished 'lintjson' after 1.1 min
[INFO] [10:51:13] Finished 'jsoncopy' after 1.08 min
[INFO] [10:51:13] Starting 'htmlcopy'...
[INFO] [10:51:13] copying html files for making it ready for templatecache
[INFO] [10:51:14] Finished 'linthtml' after 1.12 min
[INFO] [10:51:16] Finished 'lintjs' after 1.17 min
[INFO] [10:51:16] Starting 'wireindex'...
[INFO] [10:51:16] Linking all js/css files into index.html
[INFO] [10:51:17] gulp-inject 100 files into index.html.
[INFO] [10:51:17] gulp-inject 3 files into index.html.
[INFO] [10:51:17] Finished 'wireindex' after 705 ms
[INFO] [10:51:17] Finished 'htmlcopy' after 3.21 s
[INFO] [10:51:17] Starting 'fontscopy'...
[INFO] [10:51:17] copying bootstrap and other fonts
[INFO] [10:51:17] Finished 'fontscopy' after 224 ms
[INFO] [10:51:17] Starting 'templatecache'...
[INFO] [10:51:17] creating AngularJS $templateCache
[INFO] [10:51:18] Finished 'templatecache' after 824 ms
[INFO] [10:51:18] Starting 'optimize'...
[INFO] [10:51:18] optimizing the js/html/css files
[INFO] [10:51:19] gulp-inject 1 files into index.html.
[INFO] [10:51:31] Finished 'optimize' after 13 s
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # artifactname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Softwares\workspace_eclipse\artifactname\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) # artifactname ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # artifactname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Softwares\workspace_eclipse\artifactname\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) # artifactname ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # artifactname ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) # artifactname ---
[INFO] Packaging webapp
[INFO] Assembling webapp [artifactname] in [D:\Softwares\workspace_eclipse\artifactname\target\pva-ui-webapp]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\Softwares\workspace_eclipse\artifactname\src\main\webapp]
[INFO] Webapp assembled in [600 msecs]
[INFO] Building war: D:\Softwares\workspace_eclipse\artifactname\target\pva-ui-webapp.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # artifactname ---
[INFO] Installing D:\Softwares\workspace_eclipse\artifactname\target\pva-ui-webapp.war to C:\Users\Admin\.m2\repository\com\mycompany\artifactname\0.2.0\artifactname-0.2.0.war
[INFO] Installing D:\Softwares\workspace_eclipse\artifactname\pom.xml to C:\Users\Admin\.m2\repository\com\mycompany\artifactname\0.2.0\artifactname-0.2.0.pom
[INFO]
[INFO] --- frontend-maven-plugin:1.4:install-node-and-npm (install node and npm) # artifactname ---
[INFO] Node v6.10.0 is already installed.
[INFO] NPM 3.10.10 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.4:npm (npm install) # artifactname ---
[INFO] Running 'npm install' in D:\Softwares\workspace_eclipse\artifactname
[WARNING] npm WARN artifactname#0.2.0 No repository field.
[INFO]
[INFO] --- frontend-maven-plugin:1.4:bower (bower install) # artifactname ---
[INFO] Running 'bower install' in D:\Softwares\workspace_eclipse\artifactname
[INFO]
[INFO] --- frontend-maven-plugin:1.4:gulp (gulp build) # artifactname ---
[INFO] Running 'gulp optimize --env local2' in D:\Softwares\workspace_eclipse\artifactname
[INFO] [10:51:48] Using gulpfile D:\Softwares\workspace_eclipse\artifactname\gulpfile.js
[INFO] [10:51:48] Starting 'lintjs'...
[INFO] [10:51:48] Analyzing JS files
[INFO] [10:51:49] Starting 'linthtml'...
[INFO] [10:51:49] Analyzing HTML files
[INFO] [10:51:49] Starting 'lintcss'...
[INFO] [10:51:49] Analyzing CSS files
[INFO] [10:51:49] Starting 'lintjson'...
[INFO] [10:51:49] Analyzing JSON files
[INFO] [10:51:49] Starting 'clean'...
[INFO] [10:51:49] cleaning ./src/main/webapp/js/,./src/main/webapp/fonts/,./src/main/webapp/resources/,./src/main/webapp/styles/,./src/main/webapp/index.html,./src/main/webapp/rev-manifest.json,./.tmp/
[ERROR] The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information
[INFO] [10:51:50] Finished 'clean' after 1.05 s
[INFO] [10:51:50] Starting 'jsoncopy'...
[INFO] [10:51:50] copying and minifying json resources
[INFO] [10:51:52] Finished 'lintcss' after 3.29 s
[INFO] [10:52:56] Finished 'lintjson' after 1.12 min
[INFO] [10:52:58] Finished 'jsoncopy' after 1.12 min
[INFO] [10:52:58] Starting 'htmlcopy'...
[INFO] [10:52:58] copying html files for making it ready for templatecache
[INFO] [10:52:58] Finished 'linthtml' after 1.13 min
[INFO] [10:53:00] Finished 'lintjs' after 1.18 min
[INFO] [10:53:00] Starting 'wireindex'...
[INFO] [10:53:00] Linking all js/css files into index.html
[INFO] [10:53:01] gulp-inject 100 files into index.html.
[INFO] [10:53:01] gulp-inject 3 files into index.html.
[INFO] [10:53:01] Finished 'wireindex' after 568 ms
[INFO] [10:53:01] Finished 'htmlcopy' after 3.04 s
[INFO] [10:53:01] Starting 'fontscopy'...
[INFO] [10:53:01] copying bootstrap and other fonts
[INFO] [10:53:01] Finished 'fontscopy' after 182 ms
[INFO] [10:53:01] Starting 'templatecache'...
[INFO] [10:53:01] creating AngularJS $templateCache
[INFO] [10:53:02] Finished 'templatecache' after 805 ms
[INFO] [10:53:02] Starting 'optimize'...
[INFO] [10:53:02] optimizing the js/html/css files
[INFO] [10:53:02] gulp-inject 1 files into index.html.
[INFO] [10:53:15] Finished 'optimize' after 13 s
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # artifactname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Softwares\workspace_eclipse\artifactname\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) # artifactname ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # artifactname ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Softwares\workspace_eclipse\artifactname\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) # artifactname ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # artifactname ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) # artifactname ---
[INFO] Packaging webapp
[INFO] Assembling webapp [artifactname] in [D:\Softwares\workspace_eclipse\artifactname\target\pva-ui-webapp]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\Softwares\workspace_eclipse\artifactname\src\main\webapp]
[INFO] Webapp assembled in [312 msecs]
[INFO] Building war: D:\Softwares\workspace_eclipse\artifactname\target\pva-ui-webapp.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:27 min
[INFO] Finished at: 2017-07-19T10:53:15+05:30
[INFO] Final Memory: 12M/122M
[INFO] ------------------------------------------------------------------------
Notice that the frontend-maven-plugin is executed twice. This almost doubles up the build time.
How do I make it run only once?

You are getting multiple executions because you have specified multiple default lifecycle phases on the command line:
mvn clean install package -DenvType=local2
This will:
run the clean lifecycle;
run the default lifecycle up to and including install (which includes package);
run the default lifecycle again up to and including package.
Please see Introduction to the Build Lifecycle for more information.

Related

How can I fix the unexpected clean phase caused by maven 3.3.9's build order and use ${revision}

I have a multi-module maven project, it's a springboot project.
Because of our company's jenkins script, I need to copy the runnable module(with the spring main class) to the root pom menu and I use Maven CI Friendly Versions's placeholder ${revision} to make the version simplify, but it's not work because the build order deleted the .jar file in maven 3.3.9 after copy, and it's works when the maven version is 3.8.2.
I write a demo project to reproduce the problem, the root pom is called demo-root, and a web module called demo-web.
Here's my root pom
<?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>org.example</groupId>
<artifactId>demo-root</artifactId>
<version>${revision}</version>
<modules>
<module>demo-web</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<revision>1.0-SNAPSHOT</revision>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>demo-web</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here's my module pom:
<?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">
<parent>
<artifactId>demo-root</artifactId>
<groupId>org.example</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>demo-web</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>demo-project</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.example</groupId>
<artifactId>demo-web</artifactId>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>demo-project.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>../target</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then, I run the mvn clean package under the root dir(with the .pom file).
Here's the build log, we can see that the build order is 'demo-web' -> 'demo-root'.
And under the log we can see that build order make the clean after the copy, that deleted the .jar file.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-web
[INFO] demo-root
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-root 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] demo-web ........................................... SUCCESS [ 4.592 s]
[INFO] demo-root .......................................... SUCCESS [ 0.095 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.940 s
[INFO] Finished at: 2021-10-26T00:44:10+08:00
[INFO] Final Memory: 34M/120M
[INFO] ------------------------------------------------------------------------
If I change the maven version to 3.8.2, and then run the mvn clean package.
it works well.
Here's the build log, and under the log we can see that the build order is 'demo-root' ->
'demo-web', so the copy is after the clean delete, and we can get the .jar file.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-root [pom]
[INFO] demo-web [jar]
[INFO]
[INFO] -----------------------< org.example:demo-root >------------------------
[INFO] Building demo-root 1.0-SNAPSHOT [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO]
[INFO] ------------------------< org.example:demo-web >------------------------
[INFO] Building demo-web 1.0-SNAPSHOT [2/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for demo-root 1.0-SNAPSHOT:
[INFO]
[INFO] demo-root .......................................... SUCCESS [ 1.366 s]
[INFO] demo-web ........................................... SUCCESS [ 3.800 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.653 s
[INFO] Finished at: 2021-10-26T00:48:13+08:00
[INFO] ------------------------------------------------------------------------
If I replace the ${revision} to '1.0-SNAPSHOT', it works well, and I can get a .jar file under the root's target dir.
Here is the build log:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-root
[INFO] demo-web
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-root 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] demo-root .......................................... SUCCESS [ 1.110 s]
[INFO] demo-web ........................................... SUCCESS [ 3.545 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.562 s
[INFO] Finished at: 2021-10-26T00:51:36+08:00
[INFO] Final Memory: 29M/104M
[INFO] ------------------------------------------------------------------------
So, the problem is happened with 3 pre-condition:
1、use maven-dependency-plugin to copy the module .jar file to the root dir.
2、use the ${revision} placeholder to the version tag.
3、run mvn clean package command in maven 3.3.9
How can I fix this problem when I can't change the maven version(cause the 3.3.9's a company version, change it make a lot of effect). And still want to copy the .jar to the root dir(cause the jenkins script is a company specification). And keep the ${revision} benefit to multi-version control.
If you really cannot change the Maven version, I would no use the ${revision} and instead add the versions directly.
You can then update all versions in a project by calling mvn versions:set -DnewVersion=1.2.3-SNAPSHOT

Maven - how to run compile goal only once while using openjpa plugin

When i run mvn clean compile openjpa:enhance install i noticed compile goal running twice - once before openjpa:enhance and after it (also with resources), which causes enhanced classes with openjpa:enhance to be discarded, because they are compiled again and rewritten.
How to change pom.xml or mvn command arguments so it will not run compile twice, but only once before openjpa:enhance? install at the end is needed.
pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>registry</groupId>
<artifactId>datalayer</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<includes>datalayer/dto/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>10.15.2.0</version>
</dependency>
</dependencies>
</project>
output from mvn clean compile openjpa:enhance install:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< registry:openjpaenhancingtest >--------------------
[INFO] Building openjpaenhancingtest 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # openjpaenhancingtest ---
[INFO] Deleting C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\classes
[INFO]
[INFO] --- openjpa-maven-plugin:3.1.2:enhance (default-cli) # openjpaenhancingtest ---
88 DataLayer INFO [main] openjpa.Tool - Enhancer running on type "class entities.EntityPerson".
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # openjpaenhancingtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # openjpaenhancingtest ---
[WARNING] Can't extract module name from geronimo-jta_1.1_spec-1.1.1.jar: geronimo.jta.1.1.spec: Invalid module name: '1' is not a Java identifier
[WARNING] Can't extract module name from geronimo-jms_1.1_spec-1.1.1.jar: geronimo.jms.1.1.spec: Invalid module name: '1' is not a Java identifier
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # openjpaenhancingtest ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # openjpaenhancingtest ---
[INFO] Building jar: C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\openjpaenhancingtest-0.0.1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # openjpaenhancingtest ---
[INFO] Installing C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\target\openjpaenhancingtest-0.0.1.jar to C:\Users\wortigson\.m2\repository\registry\openjpaenhancingtest\0.0.1\openjpaenhancingtest-0.0.1.jar
[INFO] Installing C:\Users\wortigson\Desktop\ISMatrikaBcWorkspace\Openjpa.Test\pom.xml to C:\Users\wortigson\.m2\repository\registry\openjpaenhancingtest\0.0.1\openjpaenhancingtest-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
You need to add openjpa:enhance to the POM itself. Then you just run mvn clean install.

Maven GAE Failed to execute goal com.google.appengine:appengine-maven-plugin:1.9.12:devserver [...] NoSuchElementException

Maven is having this problem and none of the solutions I found worked :(.
pom.xml
https://github.com/Brkk/text-share/blob/master/pom.xml
web.xml
https://github.com/Brkk/text-share/blob/master/src/main/webapp/WEB-INF/web.xml
Maven is generating
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building text-share 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> appengine-maven-plugin:1.9.12:devserver (default-cli) # text-share >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # text-share ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/paulotabarro/Desktop/workspace/text-share/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # text-share ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # text-share ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/paulotabarro/Desktop/workspace/text-share/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # text-share ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # text-share ---
[INFO]
[INFO] --- maven-war-plugin:2.4:war (default-war) # text-share ---
[INFO] Packaging webapp
[INFO] Assembling webapp [text-share] in [/Users/paulotabarro/Desktop/workspace/text-share/target/text-share-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp webResources [/Users/paulotabarro/Desktop/workspace/text-share/src/main/webapp/WEB-INF] to [/Users/paulotabarro/Desktop/workspace/text-share/target/text-share-1.0-SNAPSHOT]
[INFO] Copying webapp resources [/Users/paulotabarro/Desktop/workspace/text-share/src/main/webapp]
[INFO] Webapp assembled in [101 msecs]
[INFO] Building war: /Users/paulotabarro/Desktop/workspace/text-share/target/text-share-1.0-SNAPSHOT.war
[INFO]
[INFO] <<< appengine-maven-plugin:1.9.12:devserver (default-cli) # text-share <<<
[INFO]
[INFO] --- appengine-maven-plugin:1.9.12:devserver (default-cli) # text-share ---
[INFO]
[INFO] Google App Engine Java SDK - Running Development Server
[INFO]
[INFO] Retrieving Google App Engine Java SDK from Maven
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.692 s
[INFO] Finished at: 2014-10-14T19:12:13-08:00
[INFO] Final Memory: 16M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.appengine:appengine-maven-plugin:1.9.12:devserver (default-cli) on project text-share: Execution default-cli of goal com.google.appengine:appengine-maven-plugin:1.9.12:devserver failed. NoSuchElementException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
According to this page, https://code.google.com/p/appengine-maven-plugin/issues/detail?id=41 , you need to add the plugin not only in the <build><pluginManagement> section, but also in the <build><plugins> section. So you would need to extend your pom as follows:
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<pluginManagement>
<!-- other plugins here -->
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.12</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
</configuration>
</plugin>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Maven not running Test [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I created a new maven project in Eclipse that runs simple test by using both HtmlUnitDriver and FirefoxDriver to pull up a web page and check the title on the page. When I run maven command mvn test this is all that I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # my-app ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/Andrew/Development/code/my-app/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.049s
[INFO] Finished at: Fri Jan 31 11:53:38 EST 2014
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
When I run the same Maven command in Eclipse, it shows the following:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # my-app ---
[INFO] Surefire report directory: /Users/Andrew/Development/code/my-app/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.878s
[INFO] Finished at: Fri Jan 31 11:58:23 EST 2014
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
This is my pom.xml for those who want to check if that may be the issue:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.16</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
Did you mean to add org.apache.maven.surefire as a POM dependency under <dependencies>?
Most usages of the Surefire plugin are configured under the <pluginManagement> section:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
</pluginManagement>
</build>

Maven release:prepare goal

We have the following config in our POM file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
This ensures that the tests are not executed during test phase. Tests are executed only during integration-test phase.
However, when we prepare for release (release:prepare), maven executes the tests during test phase. This causes our build to fail because our tests can be run only during Integration test phase (we use tomcat-maven plugin to deploy the packaged war before the tests can be executed).
I know that we can skip the tests by passing the parameter (-DskipTests etc.). We do not want to skip any tests, we just want release:prepare to execute just like any other maven goal.
Any suggestion/help is highly appreciated.
Try with the more general approach to disable the maven-surefire-plugin completely during test phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<!-- Disable the default-test by putting it in phase none -->
<phase>none</phase>
</execution>
<execution>
<!-- Enable the test during integration-test phase -->
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Edit
This is the output from my dry run of mvn release:prepare with the above configured surefire plugin:
C:\Users\maba\Development\svn\local\stackoverflow\Q12840869>mvn release:prepare -DdryRun
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.0:prepare (default-cli) # Q12840869 ---
[INFO] Resuming release from phase 'scm-check-modifications'
[INFO] Verifying that there are no local modifications...
[INFO] Executing: cmd.exe /X /C "svn --non-interactive status"
[INFO] Working directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.0: :
What is SCM release tag or label for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) Q12840869-1.0: :
What is the new development version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.1-SNAPSHOT: :
[INFO] Transforming 'Q12840869-1.0-SNAPSHOT'...
[INFO] Not generating release POMs
[INFO] Executing preparation goals - since this is simulation mode it is running against the original project, not the rewritten ones
[INFO] Executing goals 'clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] [INFO] Scanning for projects...
[INFO] [INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO]
[INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # Q12840869 ---
[INFO] [INFO] Deleting C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target
[INFO] [INFO]
[INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # Q12840869 ---
[INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] [INFO] Copying 0 resource
[INFO] [INFO]
[INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # Q12840869 ---
[INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\classes
[INFO] [INFO]
[INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # Q12840869 ---
[INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] [INFO] skip non existing resourceDirectory C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\src\test\resources
[INFO] [INFO]
[INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # Q12840869 ---
[INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\test-classes
[INFO] [INFO]
[INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # Q12840869 ---
[INFO] [INFO] Building jar: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\Q12840869-1.0-SNAPSHOT.jar
[INFO] [INFO]
[INFO] [INFO] --- maven-surefire-plugin:2.7.2:test (surefire-it) # Q12840869 ---
[INFO] [INFO] Surefire report directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\surefire
-reports
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.stackoverflow.MainTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.041 sec
[INFO]
[INFO] Results :
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESS
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 5.102s
[INFO] [INFO] Finished at: Thu Oct 11 17:10:29 CEST 2012
[INFO] [INFO] Final Memory: 13M/147M
[INFO] [INFO] ------------------------------------------------------------------------
Add your integration tests in a separate profile which isn't active by default. Add a triggerring rule or something. Then invoke the builds with the integration tests on a need by need basis. For example, on your CI (Jenkins/Hudson, TeamCity, Bamboo, etc) triggered the profile.
The problem you are currently facing is that you haven't made a separation between the two types of tests and when they should run. You have simply defined the phases you would like them to execute in. This isn't sufficient knowledge of the execution context for Maven to figure out what you would like to do and it invokes them during the release as well.
I would try an alternate approach, and try to configure the release plugin to always use -DskipTests as an argument so you don't need to specify it each time:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin<artifactId>
<configuration>
<arguments>-DskipTests</arguments>
</configuration>
</plugin>
In theory this should append -DskipTests to the arguments that the prepare and release goals pass to the sub-executions of Maven that they execute.
Use the maven-failsafe-plugin for the integration tests, and keep maven-surefire-plugin for the unit tests.
This will guarantee that the unit tests are completely segregated from the integration tests (and can therefore be turned off separately), and the integration tests are run during the "integration-test and verify phases of the build lifecycle".

Categories

Resources