Maven release not calling resources:resources plugin - java

I'm trying to deploy a maven project and upgrade the versions by executing the maven release plugin on TeamCity. I am able to successfully do this - however, the resources:resources plugin is no longer executed. Or more accurately, it is executed but not doing the expected changes. When I run a maven package or install however, it works. Not sure what it is I'm missing. Any help would be appreciated.
Below is my code
Parent pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<releaseProfiles>releases</releaseProfiles>
<localCheckout>true</localCheckout>
<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%</arguments>
</configuration>
<executions>
<execution>
<id>prepare</id>
<goals>
<goal>prepare</goal>
</goals>
<configuration>
<pushChanges>false</pushChanges>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Child pom
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<!-- Adds ${buildNumber} to buildNumber.properties -->
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application_local.properties</exclude>
</excludes>
</resource>
</resources>
</build>
I run the following command:
mvn -B -e initialize release:branch release:clean release:prepare release:stage -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%...
And I have in my child project in the src/main/resources folder a file called application-deployed.properties with the following lines which is what I want to change.
# build information by team city
child.propject.buildNumber=#CONTINUOUS_BUILD_ID#
child.propject.buildVersion=#GIT_COMMIT#
child.propject.buildBranch=#GIT_BRANCH#
Any help is much appreciated

maven-resources-plugin doesn't have access to the parameters you pass in the command line. Reason for this is that deploy goal (which includes resources:resources, among others) is invoked by maven-release-plugin in a separate Maven execution.
In order to overcome this limitation, goals of maven-release-plugin accept arguments parameter that could be used to pass parameters to aforementioned separate Maven executions. Try to modify your command line the following way:
mvn -B -e initialize release:branch release:clean release:prepare release:stage -Darguments="-DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%"

I was able to solve the issue by adding the following to the maven release plugin in the parent pom
<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=${CONTINUOUS_BUILD_ID} -DGIT_COMMIT=${GIT_COMMIT} -DGIT_BRANCH=${GIT_BRANCH}</arguments>
and then calling my initial command
mvn -B -e initialize release:branch release:clean release:prepare release:stage -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%...

Related

Problem integrating web3j into maven clean install

I have a multi-module maven project where I want to generate java wrappers from .sol files, to achieve this I'm using web3j's maven plugin. Here are the (relevant sections of the) poms:
main pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.9.4</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
child pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
<configuration>
<soliditySourceFiles>
<directory>${project.basedir}/src/main/resources/solidity</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<packageName>org.example.project-name.wrappers</packageName>
<outputDirectory>
<java>${project.build.directory}/generated-sources/web3j/java</java>
</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
I'm build the project with maven with the following command: call mvn clean -U install.
The files do generate, and in the correct location, but when maven begins the compile phase of install it runs into the following error:
Compilation failure
[ERROR] /C:/source/project/project-name/src/main/java/org/example/child/TestFile.java:[4,51]
package org.example.project-name.wrappers does not exist
TestFile is an empty file that tries to import one of the generated files.
I also have an openapi code generator plugin, it does generate files properly, and I run into no issues when importing those.
I didn't find any configuration options in the web3j plugin that I missed and I also didn't find any way to help mvn install or mvn compile consider the directory in which the wrappers are generated.
I tried manually extracting the bundled calls that install makes and manually interjecting the web3j:generate-sources:
call mvn clean
call mvn web3j:generate-sources
call mvn process-resources
call mvn compile
call mvn process-test-resources
call mvn test
call mvn package
call mvn install
call mvn deploy
But this too fails at compile. I'm assuming that the web3j plugin doesn't update a variable storing all generated sources, but that's just a guess and I don't know how I would fix that.
I managed to solve the issue using org.codehaus:build-helper-maven-plugin.
I added the plugin to the dependencies of my main pom and the relevant child (I use dependency management), then added the plugin to the child's pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/web3j</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I also figured out that my assumption was correct: web3j's plugin does not update the project's sources directory.

Loading resources in a maven project with exec-maven-plugin

Having two issues here. I have a Maven project, with pom.xml specifying resources as
<resources>
<resource>
<directory>src/main/sql</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
And then I have an exec-maven-plugin section such as
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>RunMyTest</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.foo.RunMyTest</mainClass>
<classpathScope>test</classpathScope>
<addResourcesToClassPath>true</addResourcesToClassPath>
</configuration>
</execution>
</executions>
</plugin>
(Here, com/foo/RunMyTest.java lives in src/test/java).
Now, I have two issues. First, somewhat minor: if I run this with
mvn -X exec:java#RunMyTest
I see in the output [DEBUG] (f) addResourcesToClasspath = false. Does <addResourcesToClassPath>true</addResourcesToClassPath> not have any effect?
But that can be for now overridden with running
mvn exec:java#RunMyTest -DaddResourcesToClasspath=true
Now I see [DEBUG] (f) addResourcesToClasspath = true. BUT! The problem is, in my code I call code from a dependency, which in turn uses ClassLoader.getSystemClassLoader().getResource("foo.txt"); where foo.txt is under src/main/sql -- and this returns null. Testing in my code by doing RunMyTest.class.getClassLoader().getResource("foo.txt"), however, works. It appears that the system classloader does not see the resources path. Is there any nice way around it?

why maven-compiler-plugin exclude disable

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Application.java</exclude>
</excludes>
</configuration>
</plugin>
this is my pom.xml , maven-compiler-plugin.version is 3.8.1 .
but i see the Applciation.class still in my jar package by maven
You are looking at the wrong location. From what I see in the screenshot, you've found some Application file from the External Libraries. What the maven-compiler-plugin does is to generate the target folder. That's where the class file should be excluded from. Check the existence of the file class under:
target/classes/...
And don't forget to run mvn clean install before (with emphasis on clean - this will wipe out your target folder)
In a project, I had to do a similar thing, due I need to exclude the module-info.java. I resolved using this configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
If you want the entire project you can get it from GitHub. I hope this helps.

How I do implement sonar+failsafe+jacoco?

I try to implement sonar+failsafe+jacoco plugins. I added theese to my pom.xml file
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>7.5</version>
<scope>provided</scope>
</dependency>
and I added this plugins to the same file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<argLine>--add-modules java.base</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName> <!-- default: argLine -->
<includes>
<include>**/*IT.java</include>
</includes>
<destFile>${project.build.directory}/jacoco-it.exec</destFile> <!-- agent -->
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile> <!-- report -->
</configuration>
<executions>
<execution>
<id>agent</id>
<goals><goal>prepare-agent</goal></goals>
</execution>
</executions>
</plugin>
and It is already exists in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>${it.skip}</skip>
<argLine>--add-modules java.base</argLine>
<forkCount>4</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>*IT</include>
</includes>
<systemPropertyVariables>
<doc.skip>${doc.skip}</doc.skip>
</systemPropertyVariables>
</configuration>
</plugin>
and I run mvn clean verify -P integration-test and then mvn sonar:sonar
but I still get a coverage is 0.0% Why did not get IT's reports results? Please help me.. What is my issue?
I saw a mistake, which I think is the cause of your problem:
In the configuration for jacoco-maven-plugin you overrid the parameter that would receive the jvm arguments set by jacoco to communicate with maven surefire, with <propertyName>jacoco.agent.argLine</propertyName>. That means that it will fill in this property instead of the default property argLine (which is fine but not necessary I guess).
In the configuration for maven-surefire-plugin, you overrid the <argLine>--add-modules java.base</argLine> (which by default would have taken the value ${argLine}) without refering to the property jacoco.agent.argLine.
You need something like <argLine>${jacoco.agent.argLine} --add-modules java.base</argLine> or <argLine>#{jacoco.agent.argLine} --add-modules java.base</argLine> (with an #) depending on your jacoco version.
If using $and not #, you may need to define an empty <jacoco.agent.argLine/> property on top of the pom file.

maven-surefire-report-plugin not generating report.html when build is failed

maven-surefire-report-plugin cannot generate HTML reports ,when commands like
mvn clean package site
mvn site
mvn clean deploy site
aren't able to generate successfull build and it does generate HTML reports on successfull build.
When mvn site command is used it gives following error
[WARNING] Error injecting: org.apache.maven.report.projectinfo.CiManagementRepor t
java.lang.NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentCont ent
The only time HTML reports are generated whether the build is failed or not is when i run
mvn surefire-report:report
This is my master POM.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</build>
</plugins>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<showSuccess>true</showSuccess>
<outputName>Reports</outputName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
even the site folder is not generated
If you want your maven build to succeed no matter the result of the unit tests than doing like #khmarbaise suggested it is correct:
mvn clean package -Dmaven.test.failure.ignore=true
If you want your tests to fail the build but still generate a report afterwards the following did the trick for me:
mvn clean test failsafe:integration-test
mvn -Dmaven.test.skip=true surefire-report:report
(Source: https://stackoverflow.com/a/4113187/9478795)

Categories