What is making the *sources.jar during Maven release? - maven

I am certain that I do not have maven-source-plugin in my plugins, but a [project-name]-sources.jar is always getting built during release:perform. It doesn't seem to be doing it during other stages of the build life-cycle.
Unfortunately, this [project-name]-sources.jar gets uploaded to our repository (Nexus). Management wants all sources to be kept in SVN and away from the repository.
How do I do that? This is certainly not an assembly issue. We've tried different build profiles but the [project-name]-sources.jar still remained. We just don't want any source codes get uploaded to the repository during releases.
Any idea any one?
Thanks in advance.
Below is all we use in the tag:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<!-- Release Reference: http://maven.apache.org/maven-release/maven-release-plugin/index.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<tagBase>http://some.url.here</tagBase>
<checkModificationExcludes>
<checkModificationExclude>.classpath</checkModificationExclude>
<checkModificationExclude>.factorypath</checkModificationExclude>
<checkModificationExclude>.project</checkModificationExclude>
<checkModificationExclude>.rest-shell.log</checkModificationExclude>
<checkModificationExclude>.springBeans</checkModificationExclude>
<checkModificationExclude>.apt-generated/**</checkModificationExclude>
<checkModificationExclude>.settings/**</checkModificationExclude>
<checkModificationExclude>src\main\resources\rebel.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<version>${project.version}</version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

So here is the answer to my own question in case anyone wants to know the work around:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
...
<useReleaseProfile>false</useReleaseProfile>
...
</configuration>
</plugin>
</plugins>

The simply answer is that during the release run the maven-sources-plugin is attached to the build life cylce (package phase) which is activated by a property performRelease. This is defined in the super-pom which defines this are a profile.
Here is the appropriate part of the super pom:
<profiles>
<!-- NOTE: The release profile will be removed from future versions of the super POM -->
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Related

Maven Integration Testing Command

I created Maven project using Java for automation testing. When i run mvn verify it does not open any browser. What wrong with it? I can easily run testng class from eclipse but i need to run for CI/CD.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Please help. Thanks.

Running two maven profiles

My profiles in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>test-output</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>runWithHead</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>execution1</id>
<configuration>
<systemPropertyVariables>
<homepage>${ADDRESS}</homepage>
<head>true</head>
<browsers>${browser}</browsers>
<chromeDriverLocation>${chromeDriver}</chromeDriverLocation>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runHeadlessly</id>
<properties>
<displayProps>target/selenium/display.properties</displayProps>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xvfb</id>
<phase>test-compile</phase>
<goals>
<goal>xvfb</goal>
</goals>
<configuration>
<browsers>${browser}</browsers>
<displayPropertiesFile>${displayProps}</displayPropertiesFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>execution2</id>
<configuration>
<systemPropertyVariables>
<homepage>${ADDRESS}</homepage>
<head>false</head>
<display.props>${displayProps}</display.props>
<browsers>${browser}</browsers>
<chromeDriverLocation>${chromeDriver}</chromeDriverLocation>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
So first we have got shared plugins and then two different profiles.
When i try to run them with one command
mvn clean install -P runHeadlessly,runWithHead
Only plugin with xvfb id gets executed, any ideas?
(did not post the part with default property variables)
You have defined two profiles:
First profile, runWithHead, defines an execution of the maven-surefire-plugin without specifying any goal element (within a goals section), hence an empty execution
Second profile, runHeadlessly, defines an execution and goal of the selenium-maven-plugin plugin AND again an empty execution of the maven-surefire-plugin
As such, both profiles are executed, but effectively only the xvfb of the xvfb execution of the selenium-maven-plugin would be performed.
Since the maven-surefire-plugin has only one goal, test, try to add the following to both executions:
<goals>
<goal>test</goal>
<goals>
Also note: you are configuring additional executions of the maven-surefire-plugin on top of the default default-test execution which will also be executed. Hence, enabling both profiles you will end up with three executions of this plugin.

Spreading flyway profiles over phases

I'm trying to create separate profiles which using flyway-maven-plugin, but phase definition doesn't work properly. Which mean that when i use both profiles i have an error on execution because i guess "drop-create-database" using configuration from "migrate-database" thus it`s failed. Does anyone have an idea how to fix it?
<profiles>
<profile>
<id>drop-create</id>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.1</version>
<configuration>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<table>MIGRATION_LOG</table>
<sqlMigrationPrefix>EMP_</sqlMigrationPrefix>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>drop-create-database</id>
<!-- Need to garantee order of execution -->
<phase>package</phase>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>migrate</id>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.1</version>
<configuration>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<table>MIGRATION_LOG</table>
<sqlMigrationPrefix>ALL_</sqlMigrationPrefix>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>migrate-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You have to specify the configuration per execution instead of per plugin. Otherwise a later configuration for the same plugin will overwrite previous ones.
This means your pom.xml should look something like this:
<profiles>
<profile>
<id>drop-create</id>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>drop-create-database</id>
<!-- Need to garantee order of execution -->
<phase>package</phase>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
<configuration>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<table>MIGRATION_LOG</table>
<sqlMigrationPrefix>EMP_</sqlMigrationPrefix>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>migrate</id>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>migrate-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<driver>net.sourceforge.jtds.jdbc.Driver</driver>
<table>MIGRATION_LOG</table>
<sqlMigrationPrefix>ALL_</sqlMigrationPrefix>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Maven: Reporting warnings during regular compile, but not for generated sources

We have a Maven project that uses WSDL files that are turned into Java source files and later compiled.
When this project used Ant, we compiled the generated Java source file and the normal developer written Java source files separately. This allowed me to turn on deprecation and warnings on compiling the developer written Java files, but off for compiling the WSDL generated Java files. I want the developers to fix their warnings and deprecations, but I can't hold the developers responsible for code that the WSDLs generated.
Now, we've moved the project over to Maven, and I would like to do the same thing: Compile the WSDL generated Java source code without the warnings and compile the developer written Java source code with the warnings. Is it possible to do with Maven? (I mean without writing it in Ant and embedding that in the pom.xml).
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vegicorp</groupId>
<artifactId>crypto</artifactId>
<packaging>bundle</packaging>
<version>2.0.4</version> <!--package version-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<axis2.version>1.5.6</axis2.version>
<maven.dir>${project.build.directory}/maven/crypto.jar</maven.dir>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugins</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<compilerArgs>
<arg>-Xlint</arg>
<arg>Xmaxwarns</arg>
<arg>9999</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.7</version>
<configuration>
<archive>
<manifestSections>
<manifestSection>
<name>Build-Information</name>
<manifestEntries>
<Project-Name>${env.JOB_NAME}</Project-Name>
<Build-Number>${env.BUILD_NUMBER}</Build-Number>
<SVN-Revision>${env.SVN_REVISION}</SVN-Revision>
</manifestEntries>
</manifestSection>
<manifestSection>
<name>Module-Information</name>
<manifestEntries>
<Group-ID>${project.groupId}</Group-ID>
<Artifact-ID>${project.artifactId}</Artifact-ID>
<Version>${project.version}</Version>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>com.safenet.tokenization.wsclient</packageName>
<wsdlFile>src/main/wsdl/SafeNetTokenizer.wsdl</wsdlFile>
<databindingName>adb</databindingName>
<skipBuildXML>true</skipBuildXML>
<syncMode>sync</syncMode>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<targetSourceFolderLocation>generated-sources</targetSourceFolderLocation>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<reuseFork>true</reuseFork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</reporting>
<dependencies>
<!-- COMPILE -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
...
</dependencies>
</project>
Okay, I figured out how to do this, but I am not enamored with the solution:
Define two separate maven-compiler-plugin executions. One called default-compile where I compile the WSDL code, and one called main-compile where I compile the rest of the code.
Use <includes/> and <excludes> in the main-compiler-plugin execution configurations to include and exclude the code I want to compile.
I still need the build-helper-maven-plugin to define two separate source.
The default-compile is always executed (I couldn't figure out a way to turn it off) even if I don't have a configuration default-compile. That would automatically compile everything before looking at my two defined maven-compile-plugin plugin executions. To get around this, I named the WSDL compile default-compile.
Here's the mavin-compiler-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/com/safenet/**</include>
</includes>
<excludes>
<exclude>**/com/vegicorp/**</exclude>
</excludes>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>false</showDeprecation>
<showWarnings>false</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>main-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/com/vegicorp/**</include>
</includes>
<excludes>
<exclude>**/com/safenet/**</exclude>
</excludes>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
<compilerArgs>
<arg>-Xlint</arg>
<arg>Xmaxwarns</arg>
<arg>9999</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
I found David W.'s answer very useful. Unfortunately, I could not find an easy way to separate generated-sources for my current project using <includes>/<excludes> (and <testIncludes>/<testExcludes> for default-testCompile), since they appear to be checked against paths relative to compileSourceRoots.
The solution that worked best for me is to specify <compileSourceRoots> for each <execution>:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.directory}/generated-sources/swagger/src/main/java</compileSourceRoot>
</compileSourceRoots>
<showWarnings>false</showWarnings>
</configuration>
</execution>
<execution>
<id>compile-with-warnings</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.sourceDirectory}</compileSourceRoot>
</compileSourceRoots>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.build.testSourceDirectory}</compileSourceRoot>
</compileSourceRoots>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
This has the advantage of no longer requiring build-helper-maven-plugin (since ${project.compileSourceRoots} is ignored), but the disadvantage that since ${project.compileSourceRoots} is ignored, compileSourceRoot for each generator plugin must be added to an <execution> explicitly or it will not be compiled.

How to run concordion test with maven?

I am wondering how to set up maven to run concordion tests having a FooFixture.java naming convention. The tests are on the classpath in src/test/specs. I would like to do it in a separate profile.
Thanks for the help.
I finally set the tests up is by creating a different profile to run the acceptance tests.
An example given here:
<profile>
<id>acceptance-test</id>
<activation>
<property>
<name>type</name>
<value>acceptance</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-specs-source</id>
<phase>compile</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/test/specs</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<forkMode>pertest</forkMode>
<argLine>-Xms1024m -Xmx1024m</argLine>
<testFailureIgnore>false</testFailureIgnore>
<skip>false</skip>
<testSourceDirectory>src/test/specs</testSourceDirectory>
<includes>
<include>**/*Fixture.java</include>
</includes>
<systemPropertyVariables>
<propertyName>concordion.output.dir</propertyName>
<buildDirectory>target/concordion</buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
You can use the maven failsafe plugin to run unit Concordion tests in the integration-test phase. Its similar to the surefire plugin.

Resources