I have a Maven (3.0.4) project in which process some external resources, and filtering them using some properties defined in a profile.
When I launch the assembly plugin (either manually or hooked to a phase) it seems that maven-resource-plugin does not consider active the profile specified by command line. In this way the tokens which relate to the properties defined in the specified profile are not replaced.
If I define a profile activeByDefault this is considered to be active even if another is specified by command line...
This is the example:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-script</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/bash</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
...
<profiles>
<profile>
<id>staging</id>
<properties>
<remote.url>some_stag_value</remote.url>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<remote.url>some_prod_value</remote.url>
</properties>
</profile>
</profiles>
Try deactivating the profile using !:
mvn groupId:artifactId:goal -P profile_you_want !default_profile
Related
I've got a big issue with the integration of JaCoCo maven plugin for the code covering of SonarQube 6.0.
I've got a multi-module Maven project lets say :
master
|--core
|--web
|--process
in the master pom.xml, I've setted a reporting profile like that :
<profile>
<id>reporting</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-unit-test</id>
<!--<phase>test</phase> -->
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file to write the execution data to. -->
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Connection with SureFire plugin -->
<propertyName>sonarUnitTestArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to where the execution data is located. -->
<dataFile>${sonar.jacoco.reportPath}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${jacoco.ut.outputdir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>${sonarUnitTestArgLine} -XX:MaxPermSize=512M -Xms512m -Xmx512m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
in the childs, I overload the configuration by adding some exclusions :
<!-- First attempt -->
<properties>
<sonar.jacoco.excludes>**/model/**/*</sonar.jacoco.excludes>
</properties>
<!-- Second attempt -->
<properties>
<sonar.coverage.exclusions>**/model/**/*</sonar.coverage.exclusions>
</properties>
<!-- Third attempt -->
<profiles>
<profile>
<id>reporting</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude model classes (POJO's) -->
<exclude>**/model/**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
the idea here is to remove the Pojo of the code coverage ( we also do it for other types of Class ...)
When I run the mvn command line :
mvn clean generate-sources install verify -P reporting -fn
All my reports are well generated but in Sonar, the exculsions aren't been taking into account ...
Please can you help me fixing this issue ?
After a lot of reasearch, I've found the solution for this problem, I post the answers to help poeple ho'll have the same issue :
In the master-module
<properties>
<sonar.coverage.exclusions>
**/patternA/**/*,
**/patternB/**/*
</sonar.coverage.exclusions>
</properties>
In the sub-modules
<profiles>
<profile>
<id>report</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Exclude model classes (POJO's) -->
<exclude>**/patternA/**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
in the master pom
I tried adding just the below details in properties section and it worked for me.
<sonar.coverage.exclusions>
**/patternA/*.java,
**/patternB/*.java
</sonar.coverage.exclusions>
This is the profile part of pom.xml
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it
to run just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including
Arquillian tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!default</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>${skipTests}</skip>
<environment>${sv.environment}</environment>
<config-file>${test.config.file}</config-file>
<excludes>
<exclude>**/*ArqTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests
in a remote JBoss EAP instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<skipTests>false</skipTests>
<environment>${sv.environment}</environment>
<config-file>${test.config.file}</config-file>
<includes>
<include>**/*ArqTest.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-maven-plugin</artifactId>
<version>${version.shrinkwrap.resolver}</version>
<executions>
<execution>
<goals>
<goal>propagate-execution-context</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Basically, if I run maven with:
mvn clean test -Parq-jbossas-remote
*ArqTest classes are ignored because of the part that is included in the default profile:
<excludes>
<exclude>**/*ArqTest.java</exclude>
</excludes>
How can I make ignore the default profile at all if another one is specified ?
i have this structure in my maven project
src
|
|_java
|_resources
|_webapp
|
|_addin
|
|_fckconfig.dev.js
|_fckconfig.js
|_fckconfig.prod.js
my pom.xml:
<properties>
<webXmlfolder>default</webXmlfolder>
<profileVersion>defaultVersion</profileVersion>
<majorVersion>2</majorVersion>
<minorVersion>50.3-0</minorVersion>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<profileVersion>DEV</profileVersion>
<webXmlfolder>dev</webXmlfolder>
</properties>
</profile>
<profile>
<id>preprod</id>
<properties>
<profileVersion>PREPROD</profileVersion>
<webXmlfolder>preprod</webXmlfolder>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileVersion>PROD</profileVersion>
<webXmlfolder>prod</webXmlfolder>
</properties>
</profile>
</profiles>
<!-- FIN Profiles -->
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>**/*.${webXmlfolder}.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp/addin</directory>
<filtering>true</filtering>
<includes>
<include>/addin/*.${webXmlfolder}.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-web.xml</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF</outputDirectory>
<resources>
<resource>
<directory>src/main/config/${webXmlfolder}/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
when i execute mvn clean install -P prod i want to have just:
src
|
|_java
|_resources
|_webapp
|
|_addin
|
|_fckconfig.prod.js
but there is nothing going on I always file now, why?
As exaplained for maven war plugin , src/main/webapp is default folder for web application source. So, all file in src/main/webapp will be automatically added to war. Try to move addin folder outside src/main/webapp.
If you couldn't move folder, you need to work with 'exclude' tags as exaplained here.
I suggest you take advance of the maven-war-plugin to configure the contents of your WAR file based upon your profiles:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<webXml>src/main/config/${webXmlfolder}/WEB-INF/web.xml</webXml>
<warSourceIncludes>*.*</warSourceIncludes>
<warSourceIncludes>addin/*.${webXmlfolder}.js</warSourceIncludes>
</configuration>
</execution>
</executions>
</plugin>
By the way, I notice you have one possible incompatibility about the copy-web.xml plugin if you execute it at the package phase, because the war plugin always executes in that same phase, too:
Either move the copy-web.xml to an early phase.
Either take advance of the <webxml> node from the maven-war-plugin, as I have included in my scriptlet... But assuming your web.xml files do not need to be filtered. (Do they?)
Is there way to skip generate-sources in Maven?
Doing it via command line options
I've scenario where I generate CXF classes when ever I there is change in WSDL or WADL. Hence I generate it explicitly whenever I need. Hence I created a separate profile a new profile cxf-gen along with my usual dev, uat, syst. which has plugins to generate the classes. In short whenever I need to regenerate the classes I switch to the profile and run generate-sources. Here is sample profile I use.
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<envName>dev</envName>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<envName>uat</envName>
</properties>
</profile>
<profile>
<id>jaxB-gen</id>
<properties>
<envName>dev</envName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<!-- CONFIGS ->
</configuration>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>code-gen</id>
<properties>
<envName>dev</envName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- CONFIGS ->
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- wadl2java Required only when JAXRS classes are to be generated -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-wadl2java-plugin</artifactId>
<version>2.7.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- CONFIGS ->
</configuration>
<goals>
<goal>wadl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.3.7</version>
<configuration>
<!-- CONFIGS ->
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This command line option should work if you are using maven-source-plugin (works with Maven 3.6.0):
-Dmaven.source.skip=true
This is an old question and although some answers would somehow work none of them are ideal.
This answer does not break clean builds: calling "mvn <goal>" still produces the expected and backward-compatible result, which is good for continuous integration. Also this answer does not rely on committing generated code to version control, which is a bad idea as it might become out of sync with the source.
I am assuming the generate-sources phase is bound to a plugin goal.
The answer is to create a profile called "clean-build" which is active by default and contains your plugin binding. When a developer trusts they can safely skip generate-sources they may run the following.
mvn -P !clean-build <goal>
Or if the exclamation mark needs to be escaped.
mvn -P \!clean-build <goal>
Here is what the pom.xml might look like.
<profiles>
<profile>
<id>clean-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
...
<executions>
<execution>
...
<phase>generate-sources</phase>
...
</execution>
</executions>
...
</plugin>
</plugins>
</build>
</profile>
</profiles>
This answer requires Maven 2.0.10+.
I have separated a Java EE project in the following submodules:
project-war
project-ejb
project-ear
project-test
I also have a root pom which includes the above modules. Since I have tests in a separate project, theres no point in running the test phases in the 3 first modules, as theres no point in compiling or packaging the last module since it only contains tests for the other 3 modules. My question is : How can I remove the test phases from the first 3 modules and how can I remove the other phases from the test project?
You can do that by setting up different profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
exp:
<profile>
<id>deploywar</id>
<build>
<plugins>
<plugin>
<groupId>net.fpic</groupId>
<artifactId>tomcat-deployer-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>pos</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<host>${deploymentManagerRestHost}</host>
<port>${deploymentManagerRestPort}</port>
<username>${deploymentManagerRestUsername}</username>
<password>${deploymentManagerRestPassword}</password>
<artifactSource>
address/target/addressservice.war
</artifactSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Defines the QA deployment information -->
<profile>
<id>qa</id>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<properties>
<deploymentManagerRestHost>10.50.50.50</deploymentManagerRestHost>
<deploymentManagerRestPort>58090</deploymentManagerRestPort>
<deploymentManagerRestUsername>
myotherusername
</deploymentManagerRestUsername>
<deploymentManagerRestPassword>
myotherpassword
</deploymentManagerRestPassword>
</properties>
</profile>
Which you would call the deploywar profile in a cli with mvn -Pdeploywar -Denv=dev clean install