My requirement is to create one .csv files with code coverage. I use jacococ library.Here I run my test cases in two server instances where two jacoco.exec files are created. I want to merge them into one. How to do this ?
Part of the pom.xml is given below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}</destFile>
</configuration>
</execution>
<execution>
<id>merge-all-jacoco</id>
<goals><goal>merge</goal></goals>
<phase>install</phase>
<configuration>
<destFile>merged.exec</destFile>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Related
I have a text in a java constant that I want to be replaced according to a maven variable that is configured when generating the artifacts in the following way:
public class FOO {
public static final String BASE = "/#FOO#";
}
The problem is that if I replace the java code, it is replaced forever and the replacement is no longer performed, so if I change the value of the variable it has no effect:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</plugin>
I have fixed this by doing the process in reverse:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>first-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>${my.custom.property}</token>
<value>#FOO#</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
But this second step can be dangerous, as there can be conflicts and replace something that has the same value in the java code of the class.
Another alternative would be to replace in the .class files as follows:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${basedir}/target/my-artifact-directory/WEB-INF/classes/com/my/package//Constants$PATHS.class</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</plugin>
The replacement works but the application does not start correctly.
Any other ideas on how to perform the replacement without modifying the original code?
I'd create a resource file in src/main/resources that is read in FOO and use the Maven Resources Plugin's Resource Filtering similar to the answer to spring maven profile - set properties file based on compilation profile:
foo.properties
BASE=${propertyName}
pom.xml
<project>
...
<properties>
<propertyName>property value</propertyName>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
...
I am using TestNG and maven failsafe for my integration tests.
The tests are executed and they pass however there are absolutely no details printed out.
I even created a dummy test and have System.out.println in that and none of that is printed out.
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
<properties>
<property>
<name>surefire.testng.verbose</name>
<value>10</value>
</property>
</properties>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
I want the testNG summary to be printed and logging statements to be printed ...
I am also using the groovy-eclipse-compiler plugin .. not sure if that makes a difference though
When you use a testing framework, you need to use the maven surefire plugin to have a summary of your results. I dont think that anything is executed the way you do it right now, so no output is expectable.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/main/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<skipTests>${skipTests}</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
I'm using javafx-maven plugin to create a javafx webstart application. I had some issues signing the jar files with the javafx-maven plugin. what I want to do is, package(jar) the application with javafx-maven plugin and then sign the jar files using maven-jarsigner-plugin .
How do i execute the maven-jarsigner-plugin to sign my files after the application is packaged?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>target/jfx/app/</archiveDirectory>
<includes>
<include>**/*.jar</include>
</includes>
<keystore>path tp keystore</keystore>
<alias>alias</alias>
<storepass>password</storepass>
<keypass>password</keypass>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.3.0</version>
<configuration>
<bundler>jnlp</bundler>
<mainClass>com.myorg.myapp.launcher.myappLauncher</mainClass>
<bundleArguments>
<jnlp.allPermisions>true</jnlp.allPermisions>
<jnlp.includeDT>true</jnlp.includeDT>
<jnlp.outfile>myapp</jnlp.outfile>
</bundleArguments>
</configuration>
</plugin>
To workaround this I moved signing to verify phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
<goal>verify</goal>
</goals>
<phase>verify</phase>
<inherited>true</inherited>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
Then I invoke maven like this:
mvn verify
Or make verify your default goal
Alternatively you can move javafx-maven plugin to the "prepare-package" phase:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.0</version>
<configuration>
<bundler>jnlp</bundler>
<mainClass>com.myorg.myapp.launcher.myappLauncher</mainClass>
<bundleArguments>
<jnlp.allPermisions>true</jnlp.allPermisions>
<jnlp.includeDT>true</jnlp.includeDT>
<jnlp.outfile>myapp</jnlp.outfile>
</bundleArguments>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>prepare-package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>
I have a project which has following structure.
Parnet
|
Module 1(create a jar)
|
Module 2(create a war)
After built this project I want to have
Parent
|
target
|
settings-include a property file which required to initialize
|
lib- include all dependency for module 1 and 2
|
run.sh-use to run
I have try with maven-assembly-plugin. But each time it is copying settings folder and run.sh only.
What is the correct way to archive my goal?
Edit:
My main pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>assembly-descriptor.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
and assembly-descriptor.xml
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>settings</directory>
</fileSet>
<fileSet>
<includes>
<include>run*</include>
<include>start*</include>
<include>log4j.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
</fileSet>
</fileSets>
I have a maven question.
I have a GWT project which generates a temporary directory gwt-unitCache folder. I'd like to remove it at the end of the build process.
I have got this plugin configuration:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
This does its job by deleting the automatically generated gwt-unitCache folder under src/main. However, it also removed the target folder which contains the classes and war file.
I don't want the target file to be removed thus I modified the configuration by removing the section:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
But this time it does not work anymore. The gwt-unitCache is not removed. It looks like the plugin is run at the beginning of the build process rather than at the end.
I am not good at Maven. Can someone help with this? How can I configure it so that:
The gwt-unitCache is removed at the end of the build process.
The target folder is not removed.
I use the command:
maven clean install
to build it.
Many thanks.
Not tested but maven-clean-plugin exposes an excludeDefaultDirectories that could help do the job. Something like:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
On a side note, I don't see why you need to clear this directory, can't you just ignore it in your SCM?
RC I use this variation to still working as usual on clean phase.
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.directory}/${project.build.finalName}/c</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
</configuration>
</execution>
</executions>
</plugin>
Since it came up in a comment: You can change the location of the cache directory like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<configuration>
<persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
</configuration>
</plugin>