I have a pom as below
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>X.0.0</modelVersion>
<parent>
<groupId>asdasd</groupId>
<artifactId>asdasd</artifactId>
<version>0.334.0-SNAPSHOT</version>
<relativePath>../something/pom.xml</relativePath>
</parent>
<!-- ======================================================================= -->
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>dfdfd</artifactId>
<name>xxxxx</name>
<packaging>content-package</packaging>
<properties>
<sonar.sources>${basedir}/src/main/angular/src</sonar.sources>
<sonar.tests>${basedir}/src/main/angular/src</sonar.tests>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/content/jcr_root</directory>
<excludes>
<exclude>**/*.iml</exclude>
</excludes>
<targetPath>jcr_root</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/content/META-INF/xxx/definition</directory>
<targetPath>../xxx/META-INF/vault/definition</targetPath>
</resource>
</resources>
<sourceDirectory>${basedir}/src/main/content/jcr_root</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
</plugin>
<!-- start frontend -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<inherited>false</inherited>
<configuration>
<nodeVersion>v16.17.0</nodeVersion>
<npmVersion>8.15.0</npmVersion>
<nodeDownloadRoot>xxxxx</nodeDownloadRoot>
<npmDownloadRoot>xxxxx</npmDownloadRoot>
<installDirectory>src/main/angular</installDirectory>
<workingDirectory>src/main/angular</workingDirectory>
</configuration>
<executions>
<execution>
......
</execution>
<execution>
<id>npm rebuild node-sass</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>rebuild node-sass</arguments>
</configuration>
</execution>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- end frontend -->
</plugins>
</build>
</project>
I want to run execution step with id npm run e2e based on profile. What I have in mind is 2 profiles default and e2eTests. With default, I can set activeByDefault as true and skip the e2e test. And when I pass e2eTests using -P , I should be able to run all execution including id=npm run e2e
I tried to move them into <profiles> but then the <sourceDirectory> was complaining. I found some links like this for it, but the problem comes on how to access plugins when I have <profiles> outside of <build>
I am not able to structure it properly.
Normally, it is not required to copy entire <build> configuration into profile definition - it should be enough to just define extra plugin execution, smth. like that:
<profiles>
<profile>
<id>e2eTests</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<executions>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
However, I would configure that in different way:
either bind execution of e2e tests to the lifecycle phase designed for that (integration-test) - in this case mvn package won't trigger e2e tests:
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
...
or take advantage of properties and profiles, for example:
<properties>
...
<skip.e2e>true</skip.e2e>
...
</properties>
<profiles>
<profile>
<id>e2eTests</id>
<properties>
<skip.e2e>false</skip.e2e>
</properties>
</profile>
</profiles>
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<skip>${skip.e2e}</skip>
<arguments>run e2e</arguments>
</configuration>
</execution>
...
Related
I have disabled all of the plugins in my module's pom.xml file and in the parent pom.xml file. I type
`mvn clean install -U`
and in the same directory
`${project.basedir}/src/main/site/resources/repo`
appears, approximately during the time the compile phase executes.
Any ideas about what could be causing this?
Edit:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<name>My Project</name>
<groupId>com.my</groupId>
<artifactId>my.parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>openid-connect-client</module>
<module>openid-connect-common</module>
<module>openid-connect-server</module>
<module>my.libraries</module>
<module>my.rest</module>
<module>my.spark-utils</module>
<module>openid-connect-server-webapp</module>
</modules>
<repositories>
<repository>
<id>HortonWorks</id>
<url>http://nexus-private.hortonworks.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.basedir>.</project.basedir>
<java.version>1.8</java.version>
<scala.tools.version>2.11</scala.tools.version>
<scala-version>${scala.tools.version}.7</scala-version>
<flyway.maven.plugin.version>4.2.0</flyway.maven.plugin.version>
<maven.war.plugin.version>3.2.2</maven.war.plugin.version>
<maven.install.plugin.version>2.5.2</maven.install.plugin.version>
<sonar.jacoco.reportPaths>
target/coverage-reports/jacoco-ut.exec,target/coverage-reports/jacoco-it.exec
</sonar.jacoco.reportPaths>
<sonar.junit.reportPaths>target/surefire-reports</sonar.junit.reportPaths>
<findbugs.annotations.version>3.0.1</findbugs.annotations.version>
<findbugs.jsr305.version>3.0.2</findbugs.jsr305.version>
<scapegoat.version>1.3.5</scapegoat.version>
<apached.server.jndi.version>1.5.5</apached.server.jndi.version>
<aws-java-sdk.version>1.11.250</aws-java-sdk.version>
<!-- Commons -->
<commons-collections4.version>4.1</commons-collections4.version>
<commons.csv.version>1.1</commons.csv.version>
<commons.fileupload.version>1.3.3</commons.fileupload.version>
<commons.lang3.version>3.5</commons.lang3.version>
<elasticsearch.version>6.2.3</elasticsearch.version>
<elasticsearch.transport.client.version>6.2.3</elasticsearch.transport.client.version>
<lucene.version>7.3.1</lucene.version>
<h2.version>1.4.192</h2.version>
<jboss.logging.version>3.3.1.Final</jboss.logging.version>
<jsoup.version>1.11.2</jsoup.version>
<jmockit.version>1.38</jmockit.version>
<jetty.version>9.4.14.v20181114</jetty.version>
<sonar.scoverage.reportPath>target/scoverage.xml</sonar.scoverage.reportPath>
<sonar.scala.scoverage.reportPath>${sonar.scoverage.reportPath}</sonar.scala.scoverage.reportPath>
<sonar.scala.scapegoat.reportPath>./target/scapegoat</sonar.scala.scapegoat.reportPath>
<sonar.scala.version>${scala-version}</sonar.scala.version>
<!-- Guava -->
<guava.version>22.0</guava.version>
<!-- Snappy -->
<snappy.version>1.0.5</snappy.version>
<!-- Spring -->
<spring.boot.version>1.5.14.RELEASE</spring.boot.version>
<spring.oauth2.version>2.1.0.RELEASE</spring.oauth2.version>
<spring.security.core>4.2.2.RELEASE</spring.security.core>
<spring.security.ldap.version>4.2.2.RELEASE</spring.security.ldap.version>
<spring.version>4.3.7.RELEASE</spring.version>
<!-- Hortonworks Ecosystem -->
<hdp.version>3.0.1.0-187</hdp.version>
<hadoop.version>3.1.1.${hdp.version}</hadoop.version>
<hbase.version>2.0.0.${hdp.version}</hbase.version>
<phoenix.version>5.0.0.${hdp.version}</phoenix.version>
<spark.version>2.3.1.${hdp.version}</spark.version>
<zookeeper.version>3.4.6.${hdp.version}</zookeeper.version>
<!-- Spark Variant -->
<!--<aehrc.variant.spark.version>0.2.0-a1</aehrc.variant.spark.version>-->
<aehrc.variant.spark.version>0.2.0-SNAPSHOT</aehrc.variant.spark.version>
<org.slf4j-version>1.7.25</org.slf4j-version>
</properties>
<profiles>
<!-- Environment Profiles -->
<profile>
<id>local</id>
<properties>
<activatedProfile>local</activatedProfile>
<!-- TODO: For all other env these will be stored on disk -->
<database.url>jdbc:postgresql://localhost:5432/my</database.url>
<database.user>username</database.user>
<database.password>password</database.password>
<postgresql.version>9.4-1200-jdbc41</postgresql.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>aws-dev</id>
<properties>
<activatedProfile>aws-dev</activatedProfile>
<!-- TODO: For all other env these will be stored on disk -->
<database.url>
jdbc:postgresql://hostname:5432/db
</database.url>
<database.user>user</database.user>
<database.password>password</database.password>
<postgresql.version>9.4-1200-jdbc41</postgresql.version>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- -Dtests.security.manager=false is needed otherwise the ESTestCase fails to initialize -->
<configuration>
<!--<argLine>-Xms128m -Xmx512m -Dtests.security.manager=false</argLine>-->
<argLine>${surefireArgLine}</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sonar</id>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<!-- The configuration is not included unless the profile is active. -->
<!-- This keeps the compiler plugin out of the equation and assists IntelliJ -->
<!-- as long as IntelliJ doesn't try to activate the sonar profile. -->
<configuration>
<scalaVersion>${scala.tools.version}</scalaVersion>
<args>
<arg>-P:scapegoat:dataDir:${sonar.scala.scapegoat.reportPath}
</arg>
<arg>-P:scapegoat:reportOnly:true</arg>
<arg>
-P:scapegoat:overrideLevels:TraversableHead=Warning:TraversableLast=Warning:OptionGet=Warning:MapGetAndGetOrElse=Warning
</arg>
</args>
<compilerPlugins>
<compilerPlugin>
<groupId>com.sksamuel.scapegoat</groupId>
<artifactId>scalac-scapegoat-plugin_${scala.tools.version}
</artifactId>
<version>${scapegoat.version}</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<dependencies>
...
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<highlighting>true</highlighting>
<scalaVersion>${scala.tools.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>instrument</id>
<goals>
<goal>pre-compile</goal>
<goal>post-compile</goal>
</goals>
</execution>
<execution>
<id>scoverage-report</id>
<goals>
<goal>report</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.3.2</version>
<executions>
<execution>
<id>add-scala-source</id>
<goals>
<goal>add-source</goal>
</goals>
</execution>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>3.0.5</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven.install.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.maven.plugin.version}</version>
<configuration>
<baselineOnMigrate>true</baselineOnMigrate>
<url>${database.url}</url>
<user>${database.user}</user>
<password>${database.password}</password>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<systemProperties>
<spring.profiles.active>${activatedProfile}</spring.profiles.active>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>com.github.alexcojocaru</groupId>
<artifactId>elasticsearch-maven-plugin</artifactId>
<!-- REPLACE THE FOLLOWING WITH THE PLUGIN VERSION YOU NEED -->
<version>6.0</version>
<configuration>
<!-- REPLACE THE FOLLOWING WITH THE ELASTICSEARCH VERSION YOU NEED -->
<version>${elasticsearch.version}</version>
<clusterName>test</clusterName>
<!--These ports must also be changed in "classpath:test/application.properties".-->
<transportPort>9301</transportPort>
<httpPort>9201</httpPort>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.14.v20181114</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
</plugin>
<plugin>
<groupId>org.appfuse.plugins</groupId>
<artifactId>warpath-maven-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.8.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-extensions</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>./target/coverage-reports/jacoco-ut.exec
</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>./target/coverage-reports/jacoco-ut.exec
</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>./target/site/jacoco-ut
</outputDirectory>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>./target/coverage-reports/jacoco-it.exec
</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for integration tests after
integration tests have been run.
-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>./target/coverage-reports/jacoco-it.exec
</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>./target/site/jacoco-it
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-requirements</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.5.3,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[${java.version},)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
The child pom:
<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>
<parent>
<groupId>com.my</groupId>
<artifactId>my.parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my.spark-utils</artifactId>
<name>SPARK-UTILS</name>
<packaging>jar</packaging>
<properties>
<scala.override.version>2.11.7</scala.override.version>
<guava.override.version>13.0.1</guava.override.version>
<jetty.override.version>9.3.19.v20170502</jetty.override.version>
</properties>
<profiles>
<profile>
<id>sonar</id>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<scalaVersion>${scala.tools.version}</scalaVersion>
<args>
<arg>-P:scapegoat:dataDir:./target/scapegoat-report</arg>
<arg>-P:scapegoat:reportOnly:true</arg>
<arg>-P:scapegoat:overrideLevels:TraversableHead=Warning:TraversableLast=Warning:OptionGet=Warning:MapGetAndGetOrElse=Warning</arg>
</args>
<compilerPlugins>
<compilerPlugin>
<groupId>com.sksamuel.scapegoat</groupId>
<artifactId>scalac-scapegoat-plugin_${scala.tools.version}</artifactId>
<version>${scapegoat.version}</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<dependencies>
...
</dependencies>
<build>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>it.unimi.dsi.fastutil</pattern>
<shadedPattern>my.it.unimi.dsi.fastutil</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>my.com.google</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/license/**</exclude>
<exclude>META-INF/*</exclude>
<exclude>META-INF/maven/**</exclude>
<exclude>LICENSE</exclude>
<exclude>NOTICE</exclude>
<exclude>/*.txt</exclude>
<exclude>build.properties</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
<finalName>my-spark-utils</finalName>
</build>
I don't have enough space to include all of the dependency information.
I'm trying to get spring-boot-maven-plugin to build two repackaged jars for two different main classes. I'added two execution blocks with their specific mainClass parameter in the configuration block but it seems that the plugin does not respect it because the configuration block is inside the execution block and not on plugin level and I always get
Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.mystuff.tools.b4commandline.Application, com.mystuff.tools.loadtester.Application]
here's the plugin section of maven-spring-boot-maven plugin of the pom.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>${artifactId}</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.mystuff.tools.loadtester.Application</mainClass>
<finalName>${artifactId}</finalName>
</configuration>
</execution>
<execution>
<id>b4-commandline</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.mystuff.tools.b4commandline.Application</mainClass>
<finalName>b4-commandline</finalName>
</configuration>
</execution>
</executions>
</plugin>
Any help on this would be great. I saw recipes on stackoverflow for the maven-plugin but those do not apply to spring-boot.
You can do this with <classifier>. Example:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<executions>
<execution>
<id>Pack application 1</id>
<phase>package</phase>
<configuration>
<finalName>application</finalName>
<mainClass>com.test.Application1</mainClass>
<outputDirectory>target/application1</outputDirectory>
<classifier>1</classifier>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>Pack application 2</id>
<phase>package</phase>
<configuration>
<finalName>application</finalName>
<mainClass>com.test.Application2</mainClass>
<outputDirectory>target/application2</outputDirectory>
<classifier>2</classifier>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
I could not make it work both within a single build (I'm not saying it is not possible though), however one option is to define 2 maven profiles:
<profiles>
<profile>
<id>one</id>
<activation>
<property>
<name>one</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.xyz.LauncherOne</mainClass>
<finalName>one</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>two</id>
<activation>
<property>
<name>two</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.xyz.LauncherTwo</mainClass>
<finalName>two</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Then, build it twice using both profiles (activated with a property in my code sample):
$ mvn -Done clean install
$ mvn -Dtwo clean install
It creates: one.jar and two.jar
Assuming its doable, doing what you are asking would mean that the 2 jars produced would be identical except their manifest's main-class attribute. I would rather suggest you to package a single jar and use spring profiles to launch it:
$ java -jar -Dspring.profiles.active=profile1 YourApp.jar
$ java -jar -Dspring.profiles.active=profile2 YourApp.jar
This allows you to define 2 application-${profile}.properties, and #Conditional configuration classes, all based on the profile name.
It seems that you must consider first execution without id and another executions with id; Then it is working.
for me below working fine:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!--<id>Batch 1(Don't put this one)</id>-->
<phase>package</phase>
<configuration>
<classifier>1</classifier>
<finalName>Core</finalName>
<mainClass>com.mainclass1</mainClass>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>Batch 2</id>
<phase>package</phase>
<configuration>
<classifier>2</classifier>
<finalName>BatchA</finalName>
<mainClass>com.mainclass2</mainClass>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>Batch 3</id>
<phase>package</phase>
<configuration>
<classifier>3</classifier>
<finalName>BatchB</finalName>
<mainClass>com.mainclass3</mainClass>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
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'm trying to figure out how to execute my JMeter performance test plan conditionally. I want to have my Jenkins CI job execute it, but when developers run mvn clean install I don't want the below plugins to run. Any ideas on how I can modify my pom.xml to conditionally run the below plugins?
Maven POM.xml JMeter Plugins:
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesDirectory>${project.basedir}/src/test/jmeter</testFilesDirectory>
<ignoreResultFailures>true</ignoreResultFailures>
<testResultsTimestamp>false</testResultsTimestamp>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/jmeter/results</dir>
<stylesheet>${project.basedir}/src/test/resources/jmeter-results-detail-report_21.xsl</stylesheet>
<outputDir>${project.build.directory}/jmeter/results</outputDir>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
<pattern>(.*?)\s(.*?)</pattern>
<replacement>$1$2</replacement>
<replaceAll>true</replaceAll>
</fileMapper>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
</plugin>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.2</version>
<executions>
<execution>
<id>send a mail</id>
<phase>install</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>false</inherited>
<configuration>
<from>admin#test.com</from>
<subject>Load Test Results</subject>
<failonerror>true</failonerror>
<mailhost>relay.apple.com</mailhost>
<htmlMessageFile>${project.build.directory}/jmeter/results/LoadTestPlan.html</htmlMessageFile>
<receivers>
<receiver>email#me.com</receiver>
</receivers>
<fileSets>
<fileSet>
<directory>${project.build.directory}/jmeter/results</directory>
<includes>
<include>LoadTestPlan.html</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
The best way to achieve this is with profiles. You define a profile which contains your plugin configuration. This profile would by default be turned off (so when a developer executes mvn clean install it is not activated), and you would only activate it during your Jenkins job.
So for example in your pom you would have something along these lines:
<project>
...
<profiles>
<profile>
<id>ci-environment</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>build.environment</name>
<value>jenkins</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<!-- rest of your jmeter configuration goes here -->
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<!-- rest of your xml-maven configuration goes here -->
</plugin>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<!-- rest of your postman configuration goes here -->
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
So by default this profile is not active, and the plugins wont execute. On Jenkins you would configure the build to be executed as follows:
mvn clean install -Dbuild.environment=jenkins
As the profile has an id you can also configure Jenkins to specifically use the profile by name as follows:
mvn clean install -Pci-environment
For details on possible ways to activate a profile see the following sonatype resource:
http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html
I'm new to Maven and I'm trying to configure Maven to generate 2 jars: one for development and one for production. The only difference between them is a config.properties file that have the database connection different so I thought I could use Maven profiles.
To my surprise I can't generate both files at once. When using profiles, each time you build you have to select the profile and a jar (in my case) will be created using the profile. The thing is that it will create 2 exactly equals jars, one without a classifier and one with the classifier (like myjar.jar and myjar-prod.jar) so if I want to generate the dev and the prod jar I have to create 4 jars (running first Maven with one profile and after that with another profile)
Why is this? Doesn't make any sense to me... but ok...
My question is:
Is there a way I could avoid the two jars from being generated? I mean, I want to have different profiles, and I have accepted (with grief) to execute multiple times the build process (one for each profile), could I avoid to have each time 2 jars and have only one without the classifier?
This is my pom.xml:
<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.p2p.</groupId>
<artifactId>LoadACHFiles</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyProject</name>
<url>http://maven.apache.org</url>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>config-*.properties</exclude>
</excludes>
</resource>
</resources>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.0</version>
<type>jar</type>
</dependency>
</dependencies>
<profiles>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!--<delete file="${project.build.outputDirectory}/config.properties"/>-->
<copy file="src/main/resources/config-prod.properties"
tofile="${project.build.outputDirectory}/config.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>prod</classifier>
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
If you are okay with having classified jars, you may do what you want without profiles, so you may have jars for all environments with a single build command. The key is to understand how Maven filtering works.
This is expanding on an answer I provided to a similar question. Start with that setup. Then:
Create config.properties in your src/main/resources, containing properties your app needs.
my.database.url=${database.url}
my.database.user=${database.user}
my.database.pw=${database.pw}
Now, create prod.properties and dev.properties in ${basedir}/src/main/filters holding appropriate values for each environment.
database.url=URL-for-dev
database.user=user-for-dev
database.pw=pw-for-dev
When you run mvn clean package, Maven will copy the contents of /src/main/resources, including config.properties, doing property replacement during the copy. Because there are multiple executions of both resources and jar plugins, Maven will create separate classified jar files. Each will contain a config.properties file, holding the correct properties for the environment. The filters will not end up in the built jars.
I made it removing the maven jar plugin in the profile section. Changed this:
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!--<delete file="${project.build.outputDirectory}/config.properties"/>-->
<copy file="src/main/resources/config-prod.properties"
tofile="${project.build.outputDirectory}/config.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>prod</classifier>
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
For this:
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!--<delete file="${project.build.outputDirectory}/config.properties"/>-->
<copy file="src/main/resources/config-prod.properties"
tofile="${project.build.outputDirectory}/config.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>