Patch versioning in Maven - maven

We have an application which has a patched version released. Now we want to deploy this patched version with some classifier stating that it is a patch version and not a normal release.
So I was trying to test the plugin locally by installing it in the local maven repository and then building the project.
I used a command similar to this to install in the local repository.
mvn install:install-file -Dfile=path/to/the/warfile -DgroupId=com.test.app -DartifactId=web-app -Dversion=default-version -Dpackaging=war -DlocalRepositoryPath=path/to/local/repo -Dclassifier=patch-version
Once the war file is installed in the local repo, I included a dependency in the pom file like this
<dependency>
<groupId>com.test.app</groupId>
<artifactId>web-app</artifactId>
<version>default-version</version>
<classifier>patch-version</classifier>
<type>war</type>
</dependency>
Now when I build the project using mvn clean package, the patched version war file is not picked up from the local repository. Instead it is downloading the default version i.e default-version from the project repository.
I want my project to use the patched version to build the project. Can someone point me to a correct usage or some other better way to do this.

Related

Conditionally include maven dependency locally instead of nexus repository

I have a project A and B. Project B uses project A as a dependency. I am publishing project A to Nexus repository when changes are tested and good to go to Nexus. However I don't want to publish project A to nexus whenever I want to test changes locally.
Is there a way to use project A's changes locally into project B without having it to be read from repository. Some condition that will make maven read project A from local rather than Nexus.
I want to keep project A in common maven dependencies rather than making changes in Maven profiles.
Maybe I am missing some obvious point but I would assume that you can just mvn install project A with a new version and adjust the dependency of A in project B to use that new version. By installing project A it should be available to be used in project B locally because it will be installed into your local Maven repository.
E.g.
In project A's pom.xml
<project>
<name>A</name>
<version>1.1.1-new-version-for-testing</version>
</project>
In project B's pom.xml
<dependencies>
<dependency>
<artifactId>A</artifactId>
<version>1.1.1-new-version-for-testing</version>
</dependency>
</dependencies>
First things first, there is a local repository on your computer that contains all the dependencies (by default in ~/.m2 but you can change that)
You can think about it as a local cache of the dependencies required to work with your own project
When you change the project A you can install the "updated" version by running mvn install on project A.
After that command project B when tested will not try to contact maven repository and will get a version of project A from your local repository.
For SNAPSHOT dependencies, maven once in a day will try to get the later version from Nexus anyway, even if you have a copy in the local repository, because working with snapshots assumes that you're OK with getting daily changes.
But then you have the following choices:
Don't work with SNAPSHOT-s at all. This is something that you shouldn't do anyway in production (I mean, when you release project B, it should contain SNAPSHOT dependencies in its pom)
When you compile project B, assuming you have all the dependencies in the local repository, use mvn <whatever> -o. This -o option means that maven should be run in offline mode, that is it won't attempt to contact a remote repository altogether. (BTW, If you want to do the opposite, which is to forcefully download all new dependencies from Nexus, you can run mvn <whatever> -U

How can I compare dependencies with a remote pom file?

We have a maven project which is part of a microservice environment. I want to find out about the latest versions of dependencies (before the release) and update my pom.xml file based on that.
Before, I was using this command:
mvn versions:compare-dependencies -DremotePom=group:artifact:version -DupdatePropertyVersions=true -DupdateDependencies=true
But now, our process is changed and we don't have a built version on our repository before the release and I need something like this:
mvn versions:compare-dependencies -DremotePomFile=http://someurl.com/path/to/our/sourcecontrol/pom.xml -DupdatePropertyVersions=true -DupdateDependencies=true
Is there any solution to use the versions plugin with a remote file instead of a remote pom from a repository?

How to update maven package after commit/pull-request

I am using a package https://github.com/dhatim/fastexcel, resently there was a commit in their repo, but the version had not been changed in Readme(description) of package in git hub, how can I update the package using maven?
I tried to run mvn release:update-versions, but I get this error
Then I run mvn release:update-versions -X
This is my pom.xml
The git repo is not equal the maven lib. You download maven libraries from the offical maven repository. The maintainer of the library needs to upload his artifact to the central repository when he builds a new release after that you can use this.
To see which version is usable you can use a maven search website like https://search.maven.org.
The dependency org.dhatim:fastexcel has a version 0.9.4 (same as the github release).
So it seems the developer already uploaded it but did not correct his Readme in the repository. So you can just use 0.9.4 in your pom.xml.
So always check the maven search site and if something is missing you can always add an issue to github to ask the developer uploading it.
There are also this more or less recommended possibilites to get library as a workaround:
Checkout and build the project by your self and add the jar file to:
something like nexus as own repository hosting (a organization normally has a maven proxy which could be used)
add it to the pom.xml as system scope dependency where the jar must be located on your system
use mvn install on the fastexcel project and change the version in your pom.xml to 0-SNAPSHOT

Boilerpipe dependency not found

According to https://github.com/Netbreeze-GmbH/boilerpipe the maven dependency for boiler pipe is
<dependency>
<groupId>de.l3s.boilerpipe</groupId>
<artifactId>boilerpipe-core</artifactId>
<version>1.2.2</version>
</dependency>
But this dependency is not available via Maven.
Closest I found is http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22de.l3s.boilerpipe%22%20AND%20a%3A%22boilerpipe%22 this dependency is version 1.1.0 . How I can add dependency 1.2.2?
Update :
I found the dependency at this location : https://mvnrepository.com/artifact/com.syncthemall/boilerpipe/1.2.2
The simply answer here is: You can't cause it does not exist in Maven Central. The location you gave https://mvnrepository.com/artifact/com.syncthemall/boilerpipe/1.2.2 is not Maven Central. This gives a location on Github repository (source repository) which hasn't deployed yet the version 1.2.2 to Maven Central...
What you might need to do is to clone the GitHub repo and build it locally and install it yourself..or best would be using a repository manager and deploy it locally in your corporate network...
You can build project with mvn clean install. That will install the artifact to your local repository. Then you can use it.
If you need it globally best you can do is to deploy the artifact (you build) to a custom maven repository. Or ask maintainers to deploy it to central repository.

Cannot get the latest version of maven plugin

I am new to maven, I have write my own maven plugin with the pom file
<groupId>com.xxx.api</groupId>
<artifactId>xxx-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
then, in my IDE (intellij) I used clean install to install my maven plugin
and in the main project, my maven plugin works fine.
However, when I modify my maven plugin by adding parameter to my mojo and "mvn clean install" ,
(the groupId,artifactId,version keep the same) it supposed to be the latest version.
However, in the main project, when I try to use the latest maven plugin, I always get the old version
i.e I cannot configure the parameter that I just add to my maven plugin (because it is not exist!)
I have try to delete the maven plugin in my .m2 repo, before I install the latest version of my maven plugin, it still not work.
Any solution that I can get the latest version of my maven plugin by keeping the same
(groupId, artifactId,version)?
thanks,
Zach
Check how the using project is configured. I guess it has its own lib/classes folder. I would suspect that your project has a copy of the older version of the plugin in its lib folder. If so, that is where it is getting the old version. Clean it out from there, i.e. you need to clean the using project.

Resources