I have two projects A and B that I build with gradle using the maven plugin. B depends on A. When I run install on project A the corresponding jar is installed into:
.m2\repository\com\mygroup\A-1.0-SNAPSHOT\
Afterwards I build B (also running install) which also installs into:
.m2\repository\com\mygroup\B-1.0-SNAPSHOT\
Now to the wierd part. If I add the eclipse plugin and generate .classpath files:
Even worse the A artifacts in .gradle and .m2 are not identical (I have tried to wipe both repos and doing a clean build)! Any ideas what goes wrong here?
And why are my projects installed into .gradle when I use the maven plugin?
Its separate projects. I have extended it a bit so now there is a project C which depends on B. When B is build its artifact is installed into .m2. When C is build it installs B into:
.gradle\caches\artifacts-14\filestore
So its actually first when building/installing C that B is dumped into .gradle\caches\artifacts-14\filestore.
Not sure I understand. If I apply the maven plugin I would expect that artifact are both installed and read from .m2. In the above example artifacts are installed into .m2 but read from .gradle\caches\artifacts-14\filestore. And since the artifacts are different between the two repos my build currently does not work.
Is it possible to completely disable .gradle\caches\artifacts-14\filestore and only use .m2. Its rather confusing to have multiple local repos especially when all 3rdparties are installed into .gradle\caches\artifacts-14\filestore instead of .m2.
The purpose of the Maven plugin is to publish to Maven repositories. It doesn’t replace Gradle’s cache. The artifacts are probably different because Gradle caches artifacts for 24 hours by default. You can overcome this with ‘–refresh-dependencies’ or by reconfiguring cache timeouts. See ResolutionStrategy in the DSL reference for the latter.
Hard to say what’s wrong without seeing your build scripts. Does B declare ‘mavenLocal()’ as a repository? Do you use ‘–refresh-dependencies’ when building B?
Yes I also build project B with --refresh-dependencies. This might have something to say though. Each project applies a custom plugin before anything else which does:
In the afterEvaluate scope a pom.xml file is read and dependencies are parsed into gradle dependencies. Could the scope of afterEvaluate have anything to say when it comes to correctly refreshing artifacts?
The suspicious thing here is the internal Maven repo before ‘mavenLocal()’. Maybe it finds A there. Once a snapshot has been found in a repository, no further repositories are searched.
EDIT: Reversing the order of the maven repos solves the problem (it tried to use the old deployed on the remote repo)
But generally when you specify a build with --refresh-dependencies should it not select the latest version (based on some timestamp info) independently of how the order of the repos are specified?
Eg. in maven it would use the one from the local cache if it was build after the version located in the remote repository.
Gradle and Maven use the same strategy here. It’s just that Gradle has its own cache and treats the local Maven repository like any other Maven repository.
Yes I solved it by reversing the order of the repos - so now mavenLocal() is always checked first.
There were some old versions in the internal repo that it used (deployed a few days ago). I cannot delete the internal repo since its used for downloading all the 3rdparties. From maven I am used to this build flow:
Check local .m2 to see if dependencies can be resolved. 2) If user builds with -U (equivalent to refresh–dependencies) check local .m2 first. Next check remote repo for and updated version. If a newer version is found in the remote repo update the local version with remote updated version and continue build.
What needs to be verified is (assuming the maven plugin is used and mavenLocal() is specified first):
User A build and deploys project X which is a dependency for project Y. 2) User B builds project Y with --refresh-dependencies. Instead of using the local X artifact the updated version from remote repo is downloaded and used. 3) User B modifies X and builds it locally. 4) User B rebuilds Y with --refresh-dependencies and now his local version of X is used instead of the remote version because the remote version of X is outdated compared to his version in .m2
As I’ve tried to explain, Gradle behaves the same. To get the behavior you are asking for, it would have to treat ‘mavenLocal()’ different from other Maven repositories, but it doesn’t currently do that. And like Maven, it will stop the search at the first repository (other than its cache) that has a snapshot.