maven versions plugin does not fetch releases with build number - maven

I have a library with version 1.0.0-19 (19 is the Jenkins build number), on next jenkins build the version 1.0.0-20 will be assigend to the library and the artifact will be deployed to a maven repository. Another artifact which is referencing the library in the pom dependency section does not get the last version if I execute versions:use-latest-versions, the dependency version is still 1.0.0-19 instead of 1.0.0-20. Maybe it has to do with the allow* system parameters, there is no property for the build number part.
Any ideas how it could be achieved to get always the last build (1.0.0-19 -> 1.0.0-20)?

Within your pom make sure you are using -
<dependencies>
<dependency>
<groupId>some.artifactory.group</groupId>
<artifactId>artifact-name</artifactId>
<version>1.0.0-19</version>
</dependency>
</dependencies>
<!-- please use the appropriate artifact and groupId -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</build>
and you are executing the command -
mvn versions:use-latest-releases
Source - http://www.mojohaus.org/versions-maven-plugin/use-latest-releases-mojo.html
Note - Just in case this also involves SNAPSHOTS, do take care of allowSnapshots and use the command as -
mvn versions:use-latest-releases -DallowSnapshots=true

Related

Specify Jacoco Version from Command Line when Running Maven Release

I have a need to specify jacoco dependency/plugin version from the command line when running the following command:
mvn release:prepare release:perform ...options... [JACOCO VERSION]
Basically, I want all projects to be built using the same jacoco version despite whatever version is present in their pom.
Is there a way to do this through the cli? I have seen examples doing this when specifying jacoco prepare agent, but I want to specify the actual jacoco-maven-plugin plugin version.
You can define the version inside the properties and set value from the command line.
For eg,
<properties>
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
While from the command line, specify the new property value.
mvn -Djacoco-maven-plugin.version=0.8.5
You can also verify the effective pom by running
mvn -Djacoco-maven-plugin.version=0.8.5 help:effective-pom

Maven Wrapper install plugins locally

I'm using Maven Wrapper for the first time and I am trying to run a command './mvnw -B openl:test' locally but I keep getting the error that no plugin found for prefix 'openl' in the current project and in the plugins groups. I looked in the .m2 directory and I do see the openl maven plugin there so I not sure why it's not working. I installed the plugin running './mvnw clean install' after added the dependency to the pom.xml file.
<dependency>
<groupId>org.openl.rules</groupId>
<artifactId>openl-maven-plugin</artifactId>
<version>5.21.9</version>
<scope>test</scope>
</dependency>
Am I missing something?
If you want to use plugins with maven you need to declare it under "plugin" section in pom.xml. In your case it would look like this:
<build>
[...]
<plugins>
[...]
<plugin>
<groupId>org.openl.rules</groupId>
<artifactId>openl-maven-plugin</artifactId>
<version>5.21.9</version>
<extensions>true</extensions>
</plugin>
</plugins>
[...]
</build>

Tycho cannot resolve dependency configured in tycho-surefire-plugin

I'm working on an Eclipse RCP + Maven project for the first time and I want to run some unit tests on my bundles with JUnit. It seems that the most recommended approach is to create a bundle fragment and use something like Tycho plugin to resolve dependencies. However, when I run mvn clean verify in my master pom, it should run the tests and deploy my application, but I'm get the following error instead:
[ERROR] Cannot resolve project dependencies:
[ERROR] You requested to install 'myproject.app.feature.feature.group 1.0.0' but it could not be found
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.21.0:test (default-test) on project myproject.app.viewmanager-test: Execution default-test of goal org.eclipse.tycho:tycho-surefire-plugin:0.21.0:test failed: No solution found because the problem is unsatisfiable.: [Unable to satisfy dependency from tycho-extra-1408913392535 0.0.0.1408913392535 to myproject.app.feature.feature.group 1.0.0.; Unable to satisfy dependency from tycho-1408913392552 0.0.0.1408913392552 to myproject.app.feature.feature.group 1.0.0.; No solution found because the problem is unsatisfiable.] -> [Help 1]
I understand that Maven is failing to find 'myproject.app.feature.feature.group 1.0.0' but I don't know where it is getting this from because it seems that the name is wrong.
It might be worth to say that when I run the unit test inside Eclipse (not with Maven) it works.
This is the Tycho configuration in my test fragment:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
<dependencies>
<dependency>
<type>eclipse-feature</type>
<artifactId>myproject.app.feature</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</configuration>
</plugin>
As suggested here, I'm adding the feature as a dependency because my test fragment requires some other bundles besides its host, so I was expecting this to work.
Any tips? The most similar issue I have found is this one, but both solutions didn't work for me.
Starting with Tycho 0.21.0, there is only limited support for declaring dependencies to reactor projects in the tycho-surefire-plugin: They only work if the test project already has some other dependency to the referenced reactor project. In your use case, where you add a dependency to a feature, this is not the case.
You could make the tycho-surefire-plugin dependencies configuration work again by adding a POM dependency to the feature project:
<dependencies>
<dependency>
<!-- Maven GAV of the feature project -->
<groupId>myproject.groupId</groupId>
<artifactId>myproject.app.feature</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<dependencies>
<dependency>
<type>eclipse-feature</type>
<artifactId>myproject.app.feature</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</configuration>
</plugin>
</plugins>
</build>
However the recommended way to specify extra test dependencies is to do this in the target-platform-configuration instead of on the tycho-surefire-plugin:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-feature</type>
<id>myproject.app.feature</id>
<versionRange>1.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
Note: The element names to specify dependencies are different in the target-platform-configuration compared to the tycho-surefire-plugin. So when migrating your configuration, you need to adapt the tag names:
<type> (unchanged)
<artifactId> → <id>
<version> → <versionRange>
Remark: Although the tag names are different, the semantics of the elements are the same: So even though the old name was <version>, the value was always interpreted as a version range. A version range that consists of a single version like 1.0.0 stands for for a version range without upper bound, i.e. version 1.0.0 or later.
I just had essentially the same problem. It seems that with tycho 0.21 dependencies have to be added using the target-platform-configuration plugin. See tycho bug 436617 comment #11 for an example.

Maven jboss plugin error: "no plugin found for prefix jboss-as"

I get the following error when trying to run the jboss-as:deploy goal.
No plugin found for prefix 'jboss-as' in the current project and in
the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]
available from the repositories [local (/home/user/.m2/repository),
central (http://repo.maven.apache.org/maven2)] -> [Help 1]
I tried out everything written here maven-javadoc-plugin and failsafe-maven-plugin missing when build JBoss Seam examples, but no luck. I need to make this plug-in work without having to add anything in the maven settings file (only in pom).
Assuming your build section has something like this in it:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<jbossHome>/usr/jboss-4.2.3.GA</jbossHome>
<serverName>all</serverName>
<fileName>target/my-project.war</fileName>
</configuration>
</plugin>
</plugins>
</build>
Then you should be using jboss:deploy instead of jboss-as:deploy. But if its like:
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.2.Final</version>
</plugin>
</plugins>
</build>
Then you should be using jboss-as:deploy instead of jboss:deploy.
Both worked for me with a fresh install of maven 3.0.4 with a bare pom.
Yes, Welsh is right.
The first one is located here and the second one here.
So, pay attention if you need to use the "jboss-as" goal specifier or the "jboss" goal specifier.

latest version of a dependency in maven archetype [duplicate]

Are there any preexisting Maven plugins or commands to update the dependencies in the POM?
Example: (if this was in my POM)
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
Is there a command or plugin I can run to get it to update the dependency to:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
Try the maven-versions-plugin, in particular, the versions:use-latest-versions goal.
I prefer using mvn versions:display-dependency-updates; this generates a report of which dependencies can be upgraded, but lets you modify the POMs yourself. There's also a display-plugin-updates command for plugins.
you can use dependencyManagement in your parent pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
this way, you need to change the version only once in the parent POM
Personally, I think there should be an additional parameter in maven that would allow you to add to the pom.xml.
See post at http://maven.40175.n5.nabble.com/Is-there-any-maven-plugin-to-add-dependency-to-existing-pom-xml-td2839092.html#a5772853
Here, you can add the following to your pom.xml file:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
...
</plugins>
...
</build>
...
</project>
...
Then backup your pom.xml file via version set command:
mvn versions:set -DnewVersion=9.9.9
Run latest versions:
mvn versions:use-latest-versions
and diff the pom.xml files, pom.xml and pom.xml.versionsBackup
No there is isn't. And be happy there is not. How would such a tool know how to upgrade your dependencies?
With breakages possibly happening between minor versions, it would be a disaster waiting to happen.
But you can always write your own Mojo for that.
get latest version of dependency from Maven repository
compare with version from pom.xml
rewrite pom.xml
run mvn test
?
Profit!
I had the same kind of problem and finally solved it by writing a bash script.
GitHub repository - Update POM Shell
This is a shell script that allows you to update a dependency on different modules directly from the command line.
It is particularly useful when you need to update one or more dependencies on different modules at once.

Resources