I have one springboot project but I wanna to deploy in my nexus to use with component in another project, so I try to remove some classes just like this:
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>br.com.lumera.balcaoonline.api.BalcaoonlineApiApplication.class</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>br/com/lumera/balcaoonline/api/BalcaoonlineApiApplication.class</exclude>
<exclude>br/com/lumera/balcaoonline/api/central/controller/rtdpj/*.class</exclude>
<exclude>**/application-*.yml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
I need to remove the controllers and the main class, but now when I try to run the project the springboot dont find the main class
how can I fix this?
tks
You can use profiles to create one jar for nexus and another not for nexus.
Maven command:
mvn install -DwithNexus=true
Example:
<profiles>
<profile>
<id>nexus</id>
<activation>
<property>
<name>withNexus</name>
</property>
</activation>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>br.com.lumera.balcaoonline.api.BalcaoonlineApiApplication.class</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>br/com/lumera/balcaoonline/api/BalcaoonlineApiApplication.class</exclude>
<exclude>br/com/lumera/balcaoonline/api/central/controller/rtdpj/*.class</exclude>
<exclude>**/application-*.yml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>no-nexus</id>
<activation>
<property>
<name>withNexus</name>
<value>!true</value>
</property>
</activation>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>br.com.lumera.balcaoonline.api.BalcaoonlineApiApplication.class</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Related
I have a class A.java and two test classes, ATest.java and AITests.java. The ITest is for integration. The tests must be performed as:
When no Maven profile is selected only the Atest must be tested.
When the itests profile is activated the both tests (ATest and AITest) must be tested.
The problems is, when I use the command
mvn -P itests test
then only the ATest is tested, without the AITest. But I have no idea what I am missing here. Any hint?
My pom.xml is:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<excludes>
<exclude>**/*ITest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>itests</id>
<activation>
<property>
<name>itests</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
For integration tests, please use the Maven failsafe plugin:
https://maven.apache.org/surefire/maven-failsafe-plugin/
You can skip it on the command line if you prefer.
I've a maven web project and I'm using profiles in pom.xml for creating .war files for different environments. See the sample below snippet from my pom.xml
...
<profiles>
<!-- DEVELOPMENT PROFILE -->
<profile>
<id>development</id>
...
<build>
...
<plugin>
<groupId>com.google.code.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
...
<configuration>
<message>Message 1</message>
</configuration>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web-development.xml</webXml>
</configuration>
</plugin>
...
</build>
</profile>
<!-- PRODUCTION PROFILE -->
<profile>
<id>production</id>
...
<build>
...
<plugin>
<groupId>com.google.code.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
...
<configuration>
<message>Message 2</message>
</configuration>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web-production.xml</webXml>
</configuration>
</plugin>
</build>
</profile>
</profiles>
However, this makes my pom.xml pretty large - I've 5 different profiles. All I wanted to do is to display a custom message and use a custom web.xml file based on the profile.
Is there a way I could add conditions in the pom.xml so that I can simplify it some like below:
...
<profiles>
<profile>
<id>development</id>
...
</profile>
<profile>
<id>production</id>
...
</profile>
<profiles>
<build>
...
<plugin>
<groupId>com.google.code.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.0.0</version>
<inherited>false</inherited>
<configuration>
<IF CONDITION TO CHECK IF development PROFILE>
<message>Message 1</message>
</IF CONDITION>
<ELSE CASE>
<message>Message 2</message>
<ELSE CASE>
</configuration>
<executions>
<execution>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<IF CONDITION TO CHECK IF development PROFILE>
<webXml>src/main/webapp/WEB-INF/web-development.xml</webXml>
</IF CONDITION>
<ELSE CASE>
<webXml>src/main/webapp/WEB-INF/web-production.xml</webXml>
<ELSE CASE>
</configuration>
</plugin>
...
</build>
No.
But you could experiment with defining properties in profiles, which might allow you to write things more concisely.
I am playing with the Maven release plugin and I am trying to bump up the pom.xml version automatically. I noticed when I do:
mvn --batch-mode release:prepare
it will automatically bump up the z version, i.e. if it is x.y.z it will be x.y.(z+1). Is there a way to bump up the y or x version without having to specify before hand what those versions should be?
I stumbled upon some blogposts on how to achieve this, and made this maven-setup which makes it possible to specify if you want to do a major, minor or patch-release:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.plugin.version}</version>
<executions>
<execution>
<id>parse-versions-for-release</id>
<phase>initialize</phase>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>major</id>
<activation>
<property>
<name>major</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>#{project.artifactId}-#{project.version}</tagNameFormat>
<useReleaseProfile>false</useReleaseProfile>
<releaseVersion>${parsedVersion.nextMajorVersion}.0.0</releaseVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>minor</id>
<activation>
<property>
<name>minor</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>#{project.artifactId}-#{project.version}</tagNameFormat>
<useReleaseProfile>false</useReleaseProfile>
<releaseVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0</releaseVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Here we use the build-helper-maven-plugin to figure out what the current (and next) version is, and we use maven profiles to specify if we want to do a major, minor or patch (default) release.
Source code can be found here: https://github.com/mortenberg80/maven-release-example
The blog posts I got inspired from were:
https://thihenos.medium.com/maven-release-plugin-a-simple-example-of-package-management-9926506acfb9
Maven release: next development version in batch mode
Is there a way that I can pass this argLine configuration to the maven-surefire plugin ONLY when <jdk.version>1.7</jdk.version> is configured for Java 1.7 but NOT when a user changes the pom.xml to be configured for java 1.8?
The reason being that Java 1.8 doesn't have permgen space.
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
You can use Maven profile activation based on properties value, in this case the property will be jdk.version and its value the different configuration of JDK. The profile will then change the Maven Surefire Plugin configuration accordingly.
Hence, your pom may look like the following:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>sample-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jdk.version>1.7</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>surefire-java7</id>
<activation>
<property>
<name>jdk.version</name>
<value>1.7</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>surefire-java8</id>
<activation>
<property>
<name>jdk.version</name>
<value>1.8</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Note the profiles section at the end. Two profiles are defined:
surefire-java7: it will be activated by the value 1.7 for the jdk.version variable and set the argLine for the Maven Surefire Plugin with the desired value
surefire-java8: it will be activated by the value 1.8 for the jdk.version variable and set a different argLine for the Maven Surefire Plugin.
Also note that with this configuration you can even switch JDK version (and as such Surefire configuration) at demand from the command line, as following:
mvn clean test -Djdk.version=1.8
The associated profile will be automatically activated as part of the build.
Important note about cross-compilation (you may already be aware of it, but just in case) I would suggest to carefully read this question/answer.
Rather than a property, you should use the JDK based activation.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>sample-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jdk.version>1.7</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>surefire-java7</id>
<activation>
<jdk>(,1.8)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>surefire-java8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Cf maven documentation.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
http://maven.apache.org/enforcer/enforcer-rules/versionRanges.html
I have a maven project for a webapp, which repack war dependency using overlays. For two profiles, test and prod, it should exclude demo.jsp file, but for other, for example local, this file should stay. Is there a way to have only one configuration for two profiles? I don't want to repeat one configuration for two profiles.
My current solution:
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT: test and prod profiles are identical
The Plugin Management may help us as the following :-
<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</pluginManagement>
</build>
Then the profiles should be as the following: -
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
...
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
...
</profile>
</profiles>
I hope this may help.