Maven release version build taking snapshot dependencies from .m2 - osgi

I have project A & B at trunk(1.5.0-SNAPSHOT) and branch (1.4.0)
B is having dependency in A
So, pom.xml for A:
<dependency>
<groupId>com.example</groupId>
<artifactId>project-B</artifactId>
<version>[1.0,2.0)</version>
<\dependency
When release build is given for A and in my ./m2 both release and snapshot jar is present i.e (B-1.5.0-SNAPSHOT) & (B-1.4.0).
(B-1.5.0-SNAPHOT) is take as a dependency even after disabling snapshot in repository level.
If (B-1.5.0-SNAPSHOT) is not there in ./m2 its is using or downloading from nexus (B-1.4.0) as dependency as expected
Note:Not using Maven release plugin
we are using Atlasssian Bamboo for maven builds so there are cases when these scenario happens. when snapshot (trunk) and release (branch) build goes one after another
So,In my case how can i restrict the snapshots as a dependency if higher version of snapshot is available in my local .m2

Related

Apache Maven - Downgrading to previous snapshot dependency version is not working

I have a maven project which is injected with a SNAPSHOT dependency 2.0.0-SNAPSHOT which is there in artifactory. Now dependency project's pom version is updated to 2.0.1-SNAPSHOT and it was built (from a jenkins job) and this snapshot is also there in artifactory. So now artifactory has both the versions 2.0.0-SNAPSHOT and 2.0.1-SNAPSHOT and on local m2 repository also both versions are there.
Main project updated the SNAPSHOT dependency to 2.0.1-SNAPSHOT and it is able to see the new changes in 2.0.1-SNAPSHOT.
Now code changes are made in 2.0.0-SNAPSHOT and it was build and updated in artifactory but now when main project reverted back to 2.0.0-SNAPSHOT and built with -U (force update snapshots), it is not able to see new change done in 2.0.0-SNAPSHOT.
Can anyone suggest what could be wrong here ?

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

Maven multi-module project only deploy -SNAPSHOT modules in mvn deploy

I have a snapshot and a release repository defined in the pom.xml of all modules
The modules in my project may be developed and updated independently, i.e. one may be updated (and hence be -SNAPSHOT) during development whereas all others are untouched with release versions
My release nexus repository prevents redeployment
Running mvn deploy will successfully deploy -SNAPSHOT projects to the snapshot repository as required but when it tries to reploy one of the unchanged modules the build fails because that module is already in the release repository
I do not want releases to be redeployable - once a release is deployed it is final
Is there a way to run "mvn deploy" such that all snapshot bundles do get deployed but release modules are skipped?

Maven - Why Does it Keep Redownloading Dependencies?

When I add a new Maven dependency that I've never used before, I will do Maven build and see the dependencies being downloaded into my local machine from Nexus. All is good.
I will then create another project, specify the same dependency with the same version, do a Maven build, and I will again see the dependencies being downloaded from Nexus into my local machine.
Why are my dependencies re-downloaded every time? Aren't these dependencies already installed in my local repository?
Maven will NOT download artifacts repeatedly. The only exceptions are if you are deleting your local repository (in ~/.m2/repository by default), you are configuring usage of a different local repository and if a new SNAPSHOT version is available.

Patch versioning in 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.

Resources