I have a fairly old maven project that uses the plugin below to write a properties file (to my understanding). I am currently updating the project dependencies and found out that the providers services have been terminated.
Is there a more up to date way of doing this, an example pom.xml extract would be great!!!
Thanks,
Adam
<profiles>
<profile>
<id>tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/appversion.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Related
I'm creating a testing framework with Java 11 and Maven, and I have build two different runners for separate tests. I want to run only one profile but it keeps running both of them. Here are my profiles:
<profiles>
<profile>
<id>smoke</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>smoke</id>
<configuration>
<includes>
<include>**/SmokeRunnerTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>functional</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>functional</id>
<configuration>
<includes>
<include>**/FunctionalRunnerTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can put
<activation>
<activeByDefault>false</activeByDefault>
</activation>
into profiles' definition to avoid unneeded profile activation.
This question already has answers here:
How to configure maven to use different log4j.properties files in different environments
(6 answers)
Closed 7 years ago.
I want to be able to use different log4j configuration for different environments. If I run project in tomcat (localhost:8080) need use dev.properties, if I run project in product server need use prod.properties. I found as described here I copied code best answer, but my pom.xml display error:
<build>
<finalName>secure-exam</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<id>log4j</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>output_directory</outputDirectory>
<resources>
<resource>${log4j.file}</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<log4j.file>/home/name/Workspace/spring/src/main/resources/console_log4j.properties</log4j.file>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<log4j.file>/home/name/Workspace/spring/src/main/resources/fiile_log4j.properties</log4j.file>
</properties>
</profile>
</profiles>
This is error show in pom.xml file
show cannot resolve sympol `copy-resources`
element outputDirectory is not allowed here
element resources is not allowed here
element resource is not allowed here
Please tell me how to configure this in my pom.xml?
EDIT
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
You didn't copy it properly. You need to use resource plugin and not compiler plugin
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
I'm setting up our system to do dual building for different versions of java artifacts based on the jdk used. There are 4 jars to build: artifact, artifact-tests, artifact-sources, and artifact-test-sources. Here is the output of the build
[INFO] Installing /Users/carlos/workspace/svn/Libraries/artifact-name/trunk/pom.xml to /Users/carlos/.m2/repository/package-path/artifact-name/1.0.8-SNAPSHOT/artifact-name-1.0.8-SNAPSHOT.pom
[INFO] Installing /Users/carlos/workspace/svn/Libraries/path/artifact-name-1.0.8-SNAPSHOT-java6.jar to /Users/carlos/.m2/repository/package-path/artifact-name/1.0.8-SNAPSHOT/artifact-name-1.0.8-SNAPSHOT-java6.jar
[INFO] Installing /Users/carlos/workspace/svn/Libraries/path/artifact-name-1.0.8-SNAPSHOT-sources.jar to /Users/carlos/.m2/repository/package-path/artifact-name/1.0.8-SNAPSHOT/artifact-name-1.0.8-SNAPSHOT-sources.jar
[INFO] Installing /Users/carlos/workspace/svn/Libraries/path/artifact-name-1.0.8-SNAPSHOT-test-sources.jar to /Users/carlos/.m2/repository/package-path/artifact-name/1.0.8-SNAPSHOT/artifact-name-1.0.8-SNAPSHOT-test-sources.jar
[INFO] Installing /Users/carlos/workspace/svn/Libraries/path/artifact-name-1.0.8-SNAPSHOT-tests.jar to /Users/carlos/.m2/repository/package-path/artifact-name/1.0.8-SNAPSHOT/artifact-name-1.0.8-SNAPSHOT-tests.jar
You can see the main artifact is built with java6 and has the appropriate classifier. I'm assuming the test classifier is overwriting the java6 classifier, but I'm unsure. Is there a way to get it to be named explicitly for both tests and the jdk? Something like -1.0.8-SNAPSHOT-tests-java6.jar. I'de like to refrain from doing manual changes to the final.name if possible and just use stock functionality like I did for the main artifact.
Here are the relevant parts of the pom.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoreNonCompile>true</ignoreNonCompile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<!--<configuration>-->
<!--<skip>true</skip>-->
<!--</configuration>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${jdk.version.display}</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>java6</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<jdk.version>1.6</jdk.version>
<jdk.version.display>java6</jdk.version.display>
</properties>
</profile>
<profile>
<id>java7</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<jdk.version>1.7</jdk.version>
<jdk.version.display>java7</jdk.version.display>
</properties>
</profile>
<profile>
<id>java8</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<jdk.version>1.8</jdk.version>
<jdk.version.display>java8</jdk.version.display>
</properties>
</profile>
</profiles>
The -sources, -tests and -test-sources JARs are themselves using classifiers. So e.g. in the case of sources, you would need to override the maven-source-plugin's <classifier> configuration option (see also Maven deploy + source classifiers). I doubt that doing this is well tested across all the tool sets that consume -sources artifacts. For example, will Eclipse still download the sources for your java6 classifier artifact if you call the classifier java6-sources? And what about the tests, test-sources and (if you need it later) javadoc classifiers—will you complicate your POM further to generate all of those differently as well? Perhaps you could make it all work, but rather than trod down that path, it would be easier to simply use two different artifactIds, one for java6 and one for java7, and leave classifiers out of the equation.
I have a maven multi module project.
root:
moduleA/ # no unit tests
moduleB/ # no unit tests
moduleC/ # no unit tests
tests/ # All unit tests, since depends on modules A, B and C
All tests are in single module called tests/ and all code is in separate modules.
Is there a way I can get code coverage?
There is a way to accomplish this. The magic is to create a combined jacoco.exec file and to do it in two steps. My pom:
<properties>
...
<jacoco.overall.exec>${maven.multiModuleProjectDirectory}/target/jacoco_analysis/jacoco.exec</jacoco.overall.exec>
</properties>
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<configuration>
<destFile>${jacoco.overall.exec}</destFile>
<dataFile>${jacoco.overall.exec}</dataFile>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>runTestWithJacoco</id>
<activation>
<property>
<name>runTestWithJacoco</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>createJacocoReport</id>
<activation>
<property>
<name>createJacocoReport</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-report</id>
<phase>validate</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Add this to your parent pom and execute mvn clean install -DrunTestWithJacoco and than mvn validate -DcreateJacocoReport. Now you have the complete coverage of a class and it doesn't matter which test covered it. The magic is to use maven.multiModuleProjectDirectory to create a combined jacoco.exec file. This property is available since maven 3.3.1 and points to the folder where you started your maven build.
I don't think either of jacoco or cobertura is capable of reporting code coverage across modules. You may want to try instrumenting the compiled classes before running the test coverage report rather than relying on on-the-fly instrumentation.
See this jacoco maven goal to perform the offline instrumentation.
Since Jacoco version: 0.7.7, you can use report-aggregate.
Root pom.xml :
<project>
[...]
<build>
<plugins>
<!-- refer:https://prismoskills.appspot.com/lessons/Maven/Chapter_06_-_Jacoco_report_aggregation.jsp -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugins>
</build>
[...]
<pluginManagement>
<plugins>
<!-- unit test plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<configuration>
<argLine>${argLine} -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
[...]
</project>
Sub-modules pom.xml:
<project>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>[path]</include>
</includes>
</configuration>
</plugin>
</plugins>
[...]
</project>
If you use Jenkin, you can just use jacoco plugin and <goal>report</goal> without other new things.
I am using maven-jetty-plugin .I have created two profile for test and development.
Here is my pom
<profiles>
<profile>
<id>test</id>
<build>
<finalName>Authorization</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>development</id>
<build>
<finalName>AuthorizationTest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So,when i run jetty:run i want to profile it for test and development.
Like
jetty:run -Ptest for test profile and jetty:run -Pdevelopment .
When i run jetty:run -Ptest it does not work.Do i need to do extra configuration to make it run? If it is not possible from plugin then is there any alternative to run jetty on different maven profile? Any help please ?
You have neither bound the jetty plug in to a phase nor did you give it a goal to execute. Contrary to many other plugins, the jetty-maven-plugin's goals are not tied to default phases. BTW: You are using a hopelessly outdated version of the jetty-plugin. Since that time, it moved away from mortbay to eclipse foundation and got a major revamp - at least one time. I have adjusted the example below accordingly:
<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.mwmahlberg.examples</groupId>
<artifactId>start-jetty-in-profiles</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Adjust to your packaging here -->
<packaging>pom</packaging>
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<!-- this will fire up jetty as soon as you reach the integration-test phase in the test profile -->
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>development</id>
</profile>
</profiles>
</project>
I defined in my IntelliJ a new maven command, as following:
clean package jetty:run -Pdev
It should work! The profile dev was used to replace params in config files during development phase.
I still use jetty plugin from mortbay:
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.4.5.v20110725</version>