I have a pom with 3 profiles defined.
I want:
- run “generate” profile always before all others (if needed)
-
run dev/normal profile based on e.g properties
pom snip:<profiles> <profile> <id>generate-axis-stubs</id> <activation> <file> <missing>target/generated-sources</missing> </file> </activation> <build> <plugins> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-wsdl2code-maven-plugin</artifactId> <configuration> <generateServerSide>true</generateServerSide> <generateServicesXml>true</generateServicesXml> <outputDirectory>target/generated-sources</outputDirectory> <packageName>${genclasses.package}</packageName> </configuration> <executions> <execution> <id>ESISGeneralSigningStatusUpdate_V1_0</id> <goals> <goal>wsdl2code</goal> </goals> <phase>generate-sources</phase> <configuration> <wsdlFile>${wsdl.src.dir}/ESISGeneralSigningStatusUpdate_V1_0.wsdl</wsdlFile> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>normal</id> <activation> <property> <name>!env</name> </property> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>**/JdbcDataServiceImplTest.java</exclude> </excludes> </configuration> </plugin> </plugins> </build> </profile> <!-- This profile should be used to run tests that requires access to DB It is activated in case system variable env=dev --> <profile> <id>run-db-tests</id> <activation> <property> <name>env</name> <value>dev</value> </property> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*Test.java</include> </includes> </configuration> </plugin> </plugins> </build> </profile>
The problem is that on clean compile this works exactly every 2nd time.
I’ve enabled the -X debug and compared the output.
– is the failed, + is the one that worked.
@@ -1551,6 +1551,10 @@
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package,
package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
+[DEBUG] Using mirror nexus (http://nexus.edb.com/nexus/content/groups/public/) for apache.snapshots (http://repository.apache.org/snapshots).
+[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
+[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
+[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
@@ -1563,7 +1567,7 @@
[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project: com.edb.esign:gssWsServer:2.3-SNAPSHOT
[DEBUG] Dependencies (collect): []
-[DEBUG] Dependencies (resolve): [compile]
+[DEBUG] Dependencies (resolve): [compile, test]
[DEBUG] Repositories (dependencies): [nexus (http://nexus.edb.com/nexus/content/groups/public/, releases+snapshots)]
[DEBUG] Repositories (plugins) : [nexus (http://nexus.edb.com/nexus/content/groups/public/, releases+snapshots)]
[DEBUG] -----------------------------------------------------------------------
When I run help:active-profile
-
after success it shows:
The following profiles are active:- normal (source: pom)
- nexus (source: settings.xml)
-
after the failed one it shows:
The following profiles are active:- generate-axis-stubs (source: pom)
- normal (source: pom)
- nexus (source: settings.xml)
If I manually clean it and then compile – it works all the time. But why doesn’t it work always for clean compile?
Thanks!
Because profiles are evaluated exactly once. So the problem isn’t
clean compile, it’s whether the foldertarget/generated-sourcesexists when you start Maven.If it exists,
clean compilehas to fail because the clean deletes the folder but Maven doesn’t care anymore.