Maven: Can't Launch Plugins on JAR project in pre-integration-test and post-integration-test phases - maven

I am writing a JAR file that acts as a client to the Jenkins CI webapp. Therefore, my project has jar packaging, not war packaging. However, for integration testing, I need to deploy the Jenkins WAR to test my JAR classes against.
I am using the cargo-maven2-plugin, and have it set up so that I can launch Jenkins from the command line with "mvn cargo:run" However, running "mvn install" gets into the integration-test phase without attempting to launch Jenkins with Cargo. In fact, the output of "mvn install -X" doesn't even mention the word "cargo".
It looks like I have bound cargo to pre-integration-test and post-integration-test correctly, but it just won't fire off.
POM below:
<?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.phoenix.build</groupId>
<artifactId>HostOp</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.port>53657</jetty.port><!-- mnemonic: 'JENKS' on a telephone -->
</properties>
<name>Host Operations</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<systemProperties>
<property>
<name>maven.output.dir</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
<systemProperties>
<JENKINS_HOME>target/test-classes/jenkins_home</JENKINS_HOME>
</systemProperties>
</container>
<configuration>
<properties>
<cargo.servlet.port>53657</cargo.servlet.port>
<cargo.jvmargs>-DJENKINS_HOME=target/test-classes/jenkins_home</cargo.jvmargs>
</properties>
<deployables>
<deployable>
<type>war</type>
<location>target/test-classes/jenkins.war</location>
<pingURL>http://localhost:53657/jenkins/view/All/newJob</pingURL>
</deployable>
</deployables>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</project>
How can I get this to fire as needed?

Your posted pom works as expected for me. I just dropped it into an empty project, and:
$ mvn install
[...]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # cargo-plugin-test ---
[...]
[INFO] --- maven-surefire-plugin:2.7.2:test (integration-tests) # cargo-plugin-test ---
[...]
[INFO] --- cargo-maven2-plugin:1.2.1:start (start-container) # cargo-plugin-test ---
[INFO] [2.ContainerStartMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-jetty:jar:1.2.1 for container jetty6x
[INFO] [beddedLocalContainer] Jetty 6.x Embedded starting...
[...]
2012-04-27 15:01:02.457:WARN::Web application not found target/test-classes/jenkins.war
2012-04-27 15:01:02.457:WARN::Failed startup of context
[...]
2012-04-27 15:01:02.741:INFO::Started SelectChannelConnector#0.0.0.0:53657
[INFO] [beddedLocalContainer] Jetty 6.x Embedded started on port [53657]
[...]
That's with Maven 3.0.3:
$ mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: /home/ryan/dev/tools/maven
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: /home/ryan/dev/tools/jdk1.7.0_03/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.0.0-17-generic", arch: "amd64", family: "unix"
I'm not sure what else it might be.

Related

Maven deploying twice

I am having an issue where my artifact is deploying twice when I run
mvn deploy
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-file) # 1.0 ---
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip (334 MB at 8.1 MB/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.pom
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.pom (423 B at 795 B/s)
Downloading from ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml
Downloaded from ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml (310 B at 1.5 kB/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml (336 B at 614 B/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip (334 MB at 7.2 MB/s)
After looking up some fixes for this I came across a potential fix:
I would simply have to added the following to the maven-assembly-plugin
<attach>false</attach>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:04 min
[INFO] Finished at: 2021-01-05T16:10:44-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project 11.8: The packaging for this project did not assign a file to the build artifact -> [Help 1]
[ERROR]
Below is what I'm currently working with. It works without the attach configuration but fails with it in there.
Any help is greatly appreciated. Thanks!
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Dev.Release.productA</groupId>
<artifactId>11.8</artifactId>
<version>https</version>
<url>https://maven.apache.org</url>
<properties>
<COMPANYRepositoryUrl>http://abc.123:8081/nexus</COMPANYRepositoryUrl>
<product>productA</product>
</properties>
<distributionManagement>
<repository>
<id>PROD</id>
<url>${PRODRepositoryUrl}/repository/PROD/</url>
</repository>
</distributionManagement>
<!--
| Where to deploy our built artifacts.
+ -->
<build>
<!--
| Define versions of plugins to ensure stable builds.
+
-->
<plugins>
<!--
| Standard maven plugins.
| Note: enforcer plugin is used (initialize) to ensure all plugins are versioned
| Or use $ mvn enforcer:enforce" to check
| Note: to check on the latest version of plugins available do:
| $ mvn versions:display-plugin-updates
+ -->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<!-- disable standard deploy -->
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
<repositoryId>TEST</repositoryId>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<url>${COMPANYRepositoryUrl}/repository/TEST/</url>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>C:\PATH\to\webui.exe</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
I had to add a section to the default execution of the maven-install-plugin. I can run mvn deploy without duplicate uploads which saves a minute in deployment time. (I also updated some of the plugins to newer versions)
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
</configuration>
</execution>
</executions>
</plugin>

Integrate jQAssistant in Maven build using profile and running server

I'm trying to integrate jQAssistant into my existing Maven build. I have a hierarchy of POMs, but basically the top POM defines what the build does. That's where I have my <pluginManagement> and my build plugins that are always used. I also have a couple of Maven profiles for special builds.
So, I want to scan all classes during build time and aggregate the results into a running server to have a fully populated Neo4J database after the build of all my Maven modules. The database should contain my whole code base.
Analysing and checking would be a different step, I don't want to do that directly when building a Maven module.
The examples I see all build a local database and then check the classes against it. As far as I understand it, I would have to run the server as a daemon and then configure the Maven plugin to use the 'bolt' URI to populate it - is this right?
Also, since I don't want to slow down the 'normal' build, I added a Maven profile to active the jQAssistant scan. However, this only works on my top POM, but doesn't work in any other Maven project/module. The inheritance of profiles is a normal and expected Maven feature - so what am I doing wrong?
Here's my parent POM. Just to see whether the profile is active, I added PMD as well:
<?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>
<packaging>pom</packaging>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.50.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
</pluginManagement>
</build>
<profile>
<id>architecture</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</project>
When I run mvn clean package -P architecture on a Maven project with that parent POM, I see the following output, which shows that the profile is active:
09:30:12.316 [INFO]
09:30:12.316 [INFO] --- maven-pmd-plugin:3.5:pmd (default) # util-type ---
09:30:15.073 [INFO]
09:30:15.073 [INFO] --- maven-pmd-plugin:3.5:cpd (default) # util-type ---
09:30:15.976 [INFO]
However, jqassistant-maven-plugin is nowhere.
Now, if I add it to my normal <build> plugins:
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
then I see the following output for mvn clean package for my parent POM:
10:38:14.252 [INFO] --- jqassistant-maven-plugin:1.5.0:scan (scan) # parent ---
10:38:15.684 [INFO] Loaded jQAssistant plugins [CDI, Common, Core Analysis, Core Report, EJB3, GraphML, JAX-RS, JPA 2, JSON, JUnit, Java, Java 8, Java EE 6, Maven 3, OSGi, RDBMS, Spring, TestNG, Tycho, XML, YAML].
10:38:15.952 [INFO] Connecting to store at 'file:/C:/jp/maven-parents/parent/target/jqassistant/store/'
10:38:20.058 [INFO] Initializing embedded Neo4j server 3.x
10:38:20.078 [INFO] Resetting store.
10:38:21.515 [INFO] Reset finished (removed 8453 nodes, 29427 relations).
10:38:22.372 [INFO] Entering C:/jp/maven-parents/parent/target/failsafe-reports
10:38:22.378 [INFO] Leaving C:/jp/maven-parents/parent/target/failsafe-reports (1 entries, 4 ms)
However, in my Maven project, I don't see any jQAssistant output.
Starting mvn help:effective-pom -Parchitecture gives me the same output for the parent project and the Maven module:
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
<configuration>
...
</configuration>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</execution>
</executions>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
In my projects I have a parent POM with the following plugin management section:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>${jqassistant.version}</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
<configuration>
<failOnSeverity>MAJOR</failOnSeverity>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I also defined the following profile, which I use to run jQAsssistant:
<profile>
<id>verify-architecture</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Using mvn -P verify-archicture clean install I can scan and analyze my projects.
Here we are, some years later :-)
And coming back to my mistake!
The problem here was the Maven phase. The jQAssistant plugin Mojo scan has the Maven phase post-integration-test by default.
However, we never do mvn clean install in my company, we only do mvn clean package and install using Jenkins, Nexus etc. etc.
So, it was my fault to not force the plugin to the package phase.
That's how it works:
<profile>
<id>jqassistant</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan-software</id>
<phase>package</phase>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

How to profile JavaFX maven project in NetBeans

When I try to profile JavaFX project in Netbeans 8.2 I get following build error:
cd C:\Users\David\Documents\NetBeansProjects\FxClock; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_101" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dexec.args.merged=true -Dexec.args=\"-agentpath:\\\"C:/Program Files/NetBeans 8.2/profiler/lib/deployed/jdk16/windows-amd64/profilerinterface.dll\\\"=\\\"C:\\Program Files\\NetBeans 8.2\\profiler\\lib\\\",5140,10 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\\Users\\David\\AppData\\Local\\NetBeans\\Cache\\8.2\\mavencachedirs\\521057086\\org-netbeans-modules-profiler -createjar -nocss2bin -appclass com.upce.fxclock.MainApp -srcdir C:\\Users\\David\\Documents\\NetBeansProjects\\FxClock\\target/classes -outdir C:\\Users\\David\\Documents\\NetBeansProjects\\FxClock\\target -outfile FxClock-1.0-SNAPSHOT.jar\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_101\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Default 'profile' action exec.args merged with maven-exec-plugin arguments declared in pom.xml.
Scanning for projects...
------------------------------------------------------------------------
Building FxClock 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-resources-plugin:2.5:resources (default-resources) # FxClock ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 5 resources
--- maven-compiler-plugin:3.1:compile (default-compile) # FxClock ---
Nothing to compile - all classes are up to date
--- exec-maven-plugin:1.2.1:exec (default-cli) # FxClock ---
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -createjar
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.158s
Finished at: Sun May 14 23:35:56 CEST 2017
Final Memory: 7M/155M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project FxClock: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
when I open the nbactions.xml, the profile action is not set, so it uses default one which fails to build.
nbactions.xml:
<actions>
<action>
<actionName>run</actionName>
<goals>
<goal>clean</goal>
<goal>package</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<runfx.args>-jar "${project.build.directory}/${project.build.finalName}.jar"</runfx.args>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>clean</goal>
<goal>package</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<runfx.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Dglass.disableGrab=true -jar "${project.build.directory}/${project.build.finalName}.jar"</runfx.args>
<jpda.listen>true</jpda.listen>
</properties>
</action>
</actions>
Is there a way to setup profiling with that <runfx.args> tag.
Here is pom.xml, I only changed the <target> & <source> to 1.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.upce</groupId>
<artifactId>FxClock</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FxClock</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.upce.fxclock.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.9</version>
</dependency>
</dependencies>
</project>
Workaround: Use external profiling
In NetBeans:
Run project normaly
Profile -> Attach to external process
Press Attach
Select the running java process to profile
This might not work when you need to profile startup of the application

How to ignore maven profiles in child module?

I want to run the simple flow, I have 6 profiles:
generate-schema,unpack-war,run-jetty,test,stop-jetty,start-stop-app
the test profile will run on a different child module when I declare it in the mvn goals/properties:
* clean --activate-profiles generate-schema,unpack-war,start-stop-app,test --projects apm-tests,apm-tests\apm-adapter-tests verify.*
How can I make the child module run only the tests and skip the rest of the profiles (generate-schema and etc.) ?
Parent pom sample:
<?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">
<project>
<parent>
<artifactId>apm-root</artifactId>
<groupId>com.apm.platform</groupId>
<version>12.50.9999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-tests</artifactId>
<packaging>pom</packaging>
<modules>
<module>alm-coverage-report</module>
</modules>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-schema</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-schema</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.apm.platform.siteadmin.setup.Setup</mainClass>
<classpathScope>test</classpathScope>
<systemProperties>
<systemProperty>
<key>InstallationFolder</key>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<key>RepositoryFolder</key>
<value>${tests.runtime}/repository</value>
</systemProperty>
<systemProperty>
<key>LogFolder</key>
<value>${tests.runtime}/log</value>
</systemProperty>
<systemProperty>
<key>mercury.td.sa_config_dir</key>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<key>CreateLabProject</key>
<value>${create.lab.project}</value>
</systemProperty>
</systemProperties>
<arguments>
<argument>--auto</argument>
<argument>${db.schema}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>start-jetty</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<war>${unpacked.war.directory}</war>
<contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
<webApp>
<contextPath>/qcbin</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>mercury.td.sa_config_dir</name>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<name>jetty.port</name>
<value>${jetty.start.port}</value>
</systemProperty>
</systemProperties>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>false</daemon>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>start-stop-app</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<war>${unpacked.war.directory}</war>
<contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
<webApp>
<contextPath>/qcbin</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>mercury.td.sa_config_dir</name>
<value>${tests.runtime}</value>
</systemProperty>
<systemProperty>
<name>jetty.port</name>
<value>${jetty.start.port}</value>
</systemProperty>
</systemProperties>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>stop-jetty</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopPort>${jetty.stop.port}</stopPort>
<stopKey>STOP</stopKey>
</configuration>
<executions>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- create project profile -->
<profile>
<id>create-project</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<serverUrl>http://localhost:${env.JETTY_PORT}/qcbin</serverUrl>
<saUser>sa</saUser>
<projectUserName>restuser</projectUserName>
<domain>UNITEST</domain>
<project>resttest</project>
<overwrite>true</overwrite>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.apm.maven.plugins.alm</groupId>
<artifactId>rest-create-project</artifactId>
<version>1.0.8.2</version>
<executions>
<execution>
<id>clean-create</id>
<phase>pre-integration-test</phase>
<goals>
<goal>create-project</goal>
</goals>
<configuration>
<serverUrl>${serverUrl}</serverUrl>
<saUser>${saUser}</saUser>
<projectUserName>${projectUserName}</projectUserName>
<projectUserPassword>${projectUserPassword}</projectUserPassword>
<domain>${domain}</domain>
<project>${project}</project>
<overwrite>${overwrite}</overwrite>
<extensions>${extensions}</extensions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Child module 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">
<parent>
<groupId>com.apm.platform</groupId>
<artifactId>apm-tests</artifactId>
<version>12.50.9999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-adapter-tests</artifactId>
<packaging>pom</packaging>
<properties>
<tests.version>${project.version}</tests.version>
</properties>
<dependencies>
<dependency>
<groupId>com.apm.platform</groupId>
<artifactId>apm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
</dependency>
</dependencies>
<profiles>
<!--run integration tests using surefire plugin -->
<profile>
<id>itest</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludedGroups>com.apm.platform.CAPQIntegrationTestCategory</excludedGroups>
<skipTests>false</skipTests>
<excludes>
<exclude>junit/**/*.java</exclude>
<exclude>org/**/*.java</exclude>
</excludes>
<argLine>-Xmx1536m</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sync-adapter</id>
<dependencies>
<dependency>
<groupId>com.apm.platform</groupId>
<artifactId>apm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<!--copies dependent classes from test-jars-->
<id>unpack-tests</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.apm.platform</groupId>
<artifactId>agm-synchronizer-adapter-testing</artifactId>
<version>1.10.9999-SNAPSHOT</version>
<classifier>test-jar-with-dependencies</classifier>
<outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
13:03:13 2015-11-30 13:03:14.422:INFO:oejs.Server:main: Started
#207555ms 13:03:13 [INFO] Started Jetty Server 13:03:13 [INFO]
13:03:13 [INFO] --- maven-surefire-plugin:2.16:test (integration-test)
# apm-tests --- 13:03:14 [INFO] No tests to run. 13:03:14 [INFO]
13:03:14 [INFO] --- jetty-maven-plugin:9.1.3.v20140225:stop
(stop-jetty) # apm-tests --- 13:03:14 [INFO] 13:03:14 [INFO] ---
maven-source-plugin:2.2.1:jar-no-fork (attach-sources) # alm-tests ---
13:03:14 2015-11-30
13:03:14.820:INFO:oejs.ServerConnector:ShutdownMonitor: Stopped
ServerConnector#4c8d3b5c{HTTP/1.1}{0.0.0.0:5729} 13:03:14 [INFO]
13:03:14 [INFO] --- maven-source-plugin:2.2.1:test-jar-no-fork
(attach-test-sources) # alm-tests --- 13:03:14 [INFO]
13:03:14 [INFO]
--------------- 13:03:14 [INFO] Building agm-synchronizer-adapter-testing
12.50.9999-SNAPSHOT 13:03:14 [INFO] ------------
Please let me clarify few important points which could also potentially solve your issue since I see some good practices may be missing in your approach:
Profiles should be used for optional/additional behaviors, while default build should always be SUCCESSFUL regardless of the declared profiles
If a module is supposed to execute tests and tests are only located in that module, then the profile should only be declared in that specific module and not in its parent. Moreover, in such a case a profile would also not be required since it would be the default module behavior. However, having a profile defined only in a module would allow you to switch it off even when executing the whole build from the parent. To switch off a profile simply use the ! or the - annotation: mvn clean install -P!profile-name as explained in the official documentation here. That will allow to ignore maven profiles in child module (to come to your questions) if the profile was only declared in that module.
You can apply the same concept to the generate-schema action: is it required in all modules? Probably not, then you can declare the profile only on the specific module requiring it and then switch it on/off as above (if by default should be on, then declare the profile as active by default).
Concerning jetty, integration tests requiring jetty should also be part of the same module, so that the module's build would follow the classic flow: start/test/stop.
If you really need to have start, test and stop in different modules, then you can follow explanation on our previous question, here.
I would also suggest to go through the Profile Pitfalls of the Maven official documentation, again, here for a better understanding of profile usage and misuses.
Additionally, if of any help, you can even skip an entire module build as part of a multimodule maven build, using the command line -pl option. Check mvn -help for further details. As such you could supply the list of modules to build. Since maven 3.2.1 you can also supply the list of modules to skip as following: mvn -pl !module-to-skip install.
When using the ! notation for skipping profiles or modules, beware that it is also a special character for bash in linux, hence put it between single quotes (mvn -pl'!module-to-skip' install). The same doesn't work on Windows however, where double quotes should be used instead (mvn -pl "!module-to-skip" install`).
Additionally, to skip modules as part of the parent build, you could also define a profile in your parent POM which re-declares the modules section and omit the modules you want to skip, as explained in this other answer.
...
<modules>
<module>module1</module>
<module>module2</module>
...
</modules>
...
<profiles>
<profile>
<id>skip-some-modules-profile</id>
<modules>
<module>module1</module>
...
<module>module-integration-test</module>
</modules>
</profile>
</profiles>
...
As such, you could craft a special multimodule build depending on the profile you want to execute.
All in all, beware that playing too much with profiles and modules which don't deliver any real artefact may affect your build readability and maintenance.

Maven ear plugin multiple artifacts content

Lets assume that I have a web project and several environments where it could be deployed. And I want Maven to build several artifacts at once (e.g. for dev an prod). I have an A-war module and an A-ear module (which contains A-war). Each war artifact could contain information which is related only to its environment.
First I configured a pom.xml file for A-war module:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory>
<webResources>
<resource>
<directory>src/env/prod</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory>
<webResources>
<resource>
<directory>src/env/dev</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<finalName>A-war</finalName>
</build>
This works fine - 2 *war*s are created in target folder: A-war-prod and A-war-dev.
Now I want to build ear artifact for each of these war.
Here is the main content of pom.xml in A-ear module:
<dependencies>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>prod</classifier>
<scope>provided</scope>
<type>war</type>
</dependency>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>A-ear</finalName>
</build>
It also builds 2 ear**s: A-ear-dev.ear and A-ear-prod.ear. And each of these *ear*s contains an A-war.war artifact. And everything would be fine except of one small detail: these **war files are the same. I mean A-ear-dev.ear contains A-war-dev.war (which is renamed to A-war.war) but A-ear-prod.ear contains the same A-war-dev.war instead of its own A-war-prod.war.
Moreover when I'd changed the order of executions (moved creating of prod higher than dev) then these *ear*s both contained A-war-prod.war.
As I can see from maven output, when starting building ear**s it copies the first war into the folder for the first **ear but for the second it does not:
[INFO] --- maven-ear-plugin:2.8:ear (package-dev) # A-ear
---
[INFO] Copying artifact [war:gr.id:A-war:dev:0.0.1-SNAPSHOT] to [/A-war.war]
[INFO] Including custom manifest ....
[INFO] Copy ear sources to ...
[INFO] Building jar: <location>\A-ear\target\A-ear-dev.ear
....
[INFO] --- maven-ear-plugin:2.8:ear (package-prod) # A-ear ---
[INFO] Copy ear sources to ...
[INFO] Including custom manifest file ...
[INFO] Building jar: <location>\A-ear\target\A-ear-prod.ear
So maybe anyone has an idea on how to force maven copy war file each time?
As I found out, when Maven is copying war file into the temp directory, it doesn't rewrite it - if there is a file with the same name, then it will not be replaced. So after the first artifact copying, it copied always the first artifact which is pointed in execution module.
All other artifacts were not copied. So this artifact was placed in all result ears.
So the solution for this issue is to specify working directory for each execution tag, like:
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<workDirectory>target/prod</workDirectory>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>

Resources