I have a mock java class, by default I would like to exclude it from the mvn install command.
But when I'm working on my local machine I would like to include it in my .war launching by command line something like: mvn clean install -DsomeProperty=true
I added this plugin to my profile:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<excludes>
<exclude>**/filter/MockFilter.java</exclude>
</excludes>
<skip>${someProperty}</skip>
</configuration>
</plugin>
But the class is always skipped. How can I include it? I give a try to this and this, but nothing worked.
Related
From Maven Surefire Plugin docs:
If you have multiple executions configured in surefire plugin within your POM, you may want to execute the only default test phase:
mvn surefire:test -Dtest=TestCircle
I didn't understand what is the priority/overriding between the POM config and the command-line.
I have these plugin configurations in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
Now I'm trying to run my tests with
mvn test -Dsurefire.includesFile=.\Path\To\includesFile -Denv=IsProfileValueTag
And I'm expecting only the classes in the includesFile to run, but all the tests with the IsProfileValueTag running.
<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.
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%...
Running $mvn test on a 64-bit Windows gives me the following error, even if I do $mvn test -Dgwt.genParam=false:
The command line is too long
Make sure you are using version 2.16 and that you have the useManifestOnlyJar option (as documented here).
For example:
<project>
[...]
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<useManifestOnlyJar>true</useManifestOnlyJar>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>
This will create jar with a manifest that re-creates your classpath (as opposed to setting it via the CLASSPATH variable which is an approach that is affected by Windows' command-line limit problem).
I imported a Maven project into IntelliJ, but it seems like it's ignoring the <configuration> specified for the surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<argLine>-Djava.endorsed.dirs=${settings.localRepository}/com/sun/metro/webservices-api/2.0.1
</argLine>
<excludes>
<exclude>**/CacheStoreTest.java</exclude>
</excludes>
</configuration>
</plugin>
When I run the tests from within the IDE, it picks up the webservices-api.jar bundled with JDK6 instead of the version from my Maven repository and it also runs the tests in CacheStoreTest even though I've indicated they should be excluded.
It's a known issue, please watch/vote.