I'm trying to run the build of a project, which has as dependence, a jar of my own.
Code dependency:
<profile>
<id>local-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>ambient</name>
<value>local</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.enterprise</groupId>
<artifactId>enterpriseUtil</artifactId>
<version>[0.0.1,)</version>
</dependency>
</dependencies>
<build>
<finalName>${finalName}</finalName>
<resources>
<resource>
<directory>src/main/resources_local</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version><!--$NO-MVN-MAN-VER$ -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<attachClasses>true</attachClasses>
<warSourceExcludes>META-INF/context.xml</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
The strangest thing is that a local build succeeds, even if I exclude the dependency from my .m2, and download from my nexus
The error:
No versions available for com.enterprise:enterpriseUtil:jar:[0.0.1,) within specified range -> [Help 1]
Related
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>
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
Maybe someone can help me. I have searched the web but haven't been able to find a solution yet.
I have a java application running on Heroku. I want to be able to have different properties files loaded for different Heroku instances (dev, test, prod), but I get java.io.FileNotFoundException. This is what I have in my pom.xml.
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>dev</value>
</property>
</activation>
<properties>
<profile.name>dev</profile.name>
</properties>
</profile>
<profile>
<id>test</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>test</value>
</property>
</activation>
<properties>
<profile.name>test</profile.name>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>prod</value>
</property>
</activation>
<properties>
<profile.name>prod</profile.name>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.0</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/profiles/${profile.name}</directory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</resource>
</resources>
</build>
How to customize the Maven build is described here:
https://devcenter.heroku.com/articles/using-a-custom-maven-settings-xml
You can create a settings file for each build type:
settings.xml <-- Default
settings-dev.xml
settings-test.xml
settings-prod.xml
A production build could then be performed as follows:
heroku config:set MAVEN_SETTINGS_PATH=settings-prod.xml
git push heroku master
Details
The Java buildpack supports a way to specify a custom Maven settings file.
By default it uses a settings file located in the build directory, this can be overridden by setting one of the following variables:
MAVEN_SETTINGS_PATH
MAVEN_SETTINGS_URL
My question had been addressed in this thread, but the explanation is not clear.
I have this build definition in one of my pom.xml files:
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
Notice that I'm using the maven-s3-wagon extension.
Next, I would like to have 2 different profiles, each with it's own settings, plugins and extensions but maven does not allow the extensions tag under a profile.
When I try using a profile:
<profiles>
<profile>
<id>local-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
I get a an error in my pom:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'extensions'. One of '{"http://maven.apache.org/POM/4.0.0":defaultGoal, "http://maven.apache.org/POM/
4.0.0":resources, "http://maven.apache.org/POM/4.0.0":testResources, "http://maven.apache.org/POM/4.0.0":directory, "http://maven.apache.org/POM/4.0.0":filters, "http://
maven.apache.org/POM/4.0.0":pluginManagement}' is expected.
Question So using the extension tag means I can't use profiles? How can I use or change build extensions via profile?
Indeed, the official Maven POM reference is not clear about the possible usage of extensions as part of a Maven profile, since it states you can have a build element within it, but not what of the build section.
However, the official Maven model effectively filters and provides what of the build section you can actually use within a profile section. And indeed extensions is not there.
However, what are Maven extensions? Build/Lifecycle enhancement, but also (and essentially): a library added to the runtime classpath of the Maven build, which participates to the build, but it is not packaged with the final artifact.
Hence, in such a scenario (if you need to have extensions in profile or have a profile to change/add an extension) you could use the following trick:
Have an harmless extension as default extension of your build (where harmless means whatever library which could be part of your build classpath and essentially not affect it at all)
Have properties defining the GAV coordinates (GroupId, ArtifactId, Version) of this extension
Have a profile which overrides these properties with the desired (useful) extension
As an example, given the following sample POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.11</extension.version>
</properties>
<build>
<extensions>
<extension>
<groupId>${extension.groupId}</groupId>
<artifactId>${extension.artifactId}</artifactId>
<version>${extension.version}</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>customize-extension</id>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.12</extension.version>
</properties>
</profile>
</profiles>
</project>
The default build (without the customize-extension profile activated), would use the default defined properties and as such add junit as build extension: this is harmless (although it may create conflicts with another junit version of your build, so make sure you use the same version of use an even more harmless library for that).
You can check Maven will pick it up by running a really first build phase, just to check information in our case, and enable the debug flag:
mvn initialize -X
And checking as part of the build log:
[DEBUG] Populating class realm extension>junit:junit:4.11
[DEBUG] Included: junit:junit:jar:4.11
Now let's use our trick: let's add (change) a build extension via profile:
mvn initialize -X -Pcustomize-extension
And as part of our build log we would have:
[DEBUG] Populating class realm extension>junit:junit:4.12
[DEBUG] Included: junit:junit:jar:4.12
Bingo. Maven picked up a different extension (in this case, a different version, the 4.12) and we succeeded on changing (or actually adding a meaningful) build extension via profile.
Just a crazy idea: use modules
Define a parent pom like this:
<groupId>org.example</groupId>
<artifactId>my-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>use-pom1</id>
<modules>
<module>pom1</module>
</modules>
</profile>
<profile>
<id>use-pom2</id>
<modules>
<module>pom2</module>
</modules>
</profile>
</profiles>
Define the desired extensions on pom1 and pom2.
I think the solution is here http://maven.apache.org/guides/mini/guide-using-extensions.html
Define a build section where extensions are defined and then into the profile set the attribute true ( like in the second profile shown below )
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.9</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>create-default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>create-core</id>
<activation>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<extensions>true</extensions>
<version>2.6</version>
<configuration>
<finalName>import-station-core-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
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.