Thorny issue of being unable to resolve jar to local .m2 repostory

I have tried to follow and understand the threads on resolving with mavenLocal and cannot get gradle to work with it. hence starting a new thread. i looked at other thread

I’m trying to run gradle v.10 with a new project and that has an org.easyrules jar dependency. when i first tried to find the maven repo via google it found a v1.0 build string, but the examples from easyrules are based on 2.2.0.

so i cloned the project from github. then ran the mvn build, and mvn clean install. This put the generated jar into my local .m2 repository ( I have no settings/xml defined in that .m2 repo). this publishes a number of jars to the repo - that contain the pom and the jar at the same time - so i get a directory created like this for example

C:\Users\William.m2\repository\org\easyrules\easyrules-core\2.2.1-SNAPSHOT, containing a easyrules-core-2.2.1-SNAPSHOT.jar, and easyrules-core-2.2.1-SNAPSHOT.pom.

so far so good.

I then go to my gradle project inside intellij and tried to add mavenLocal() (after and before mavenCentral ()).

i even tried this (and various derivatives thereof)

 repositories {
     mavenCentral()
     //mavenLocal()
     maven {
         url new File(System.getProperty("user.home"), ".m2/repository").toURI().toURL() //file:///C:/Users/William/.m2/repository'
     }
 }

to no avail. Gradle refused to resolve the jar.

In the end. I went back to google and searched harder for easyrules repo and found ref for v2.1.0, and so i removed all the local stuff and went back to remote dependency via maven central (no ‘SNAPSHOT’ this time), and gradle then refreshed and added it to the libraries.

so my simple query is this. If you get a local mvn project and build/publish to your local .m2, how do you configure build.gradle to look at the local .m2 repo to resolve. I could not get this to work

regards in advance - i just know this issue is going to hit me again one day, and i’ve wasted time trying to resolve and failed. hence ask the community.

There’s really not anything else to it. Using mavenLocal() should do the trick. Can you try running your build with --debug. You should see some entries in the extensive output that look something like:

19:04:03.506 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:/Users/mark/.m2/repository/org/foo/bar/1.0/bar-1.0.pom

Hi mark , tried that and this is the error you see

13:52:00.871 [ERROR] [org.gradle.BuildExceptionReporter]
13:52:00.881 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
13:52:00.891 [ERROR] [org.gradle.BuildExceptionReporter] Could not resolve all dependencies for configuration ‘:testCompile’.
13:52:00.904 [ERROR] [org.gradle.BuildExceptionReporter] > Could not resolve org.easyrules:easyrules-core:2.2.1-SNAPSHOT.
13:52:00.916 [ERROR] [org.gradle.BuildExceptionReporter] Required by:
13:52:00.926 [ERROR] [org.gradle.BuildExceptionReporter] softwood:rules:1.0-SNAPSHOT
13:52:00.936 [ERROR] [org.gradle.BuildExceptionReporter] > Could not resolve org.easyrules:easyrules-core:2.2.1-SNAPSHOT.
13:52:00.950 [ERROR] [org.gradle.BuildExceptionReporter] > Could not parse POM file:/C:/Users/William/.m2/repository/org/easyrules/easyrules-core/2.2.1-SNAPSHOT/easyrules-core-2.2.1-SNAPSHOT.pom
13:52:00.966 [ERROR] [org.gradle.BuildExceptionReporter] > Could not find org.easyrules:easyrules:2.2.1-SNAPSHOT.
13:52:00.979 [ERROR] [org.gradle.BuildExceptionReporter] Searched in the following locations:
13:52:00.990 [ERROR] [org.gradle.BuildExceptionReporter] file:/C:/Users/William/.m2/repository/org/easyrules/easyrules/2.2.1-SNAPSHOT/maven-metadata.xml
13:52:01.002 [ERROR] [org.gradle.BuildExceptionReporter] file:/C:/Users/William/.m2/repository/org/easyrules/easyrules/2.2.1-SNAPSHOT/easyrules-2.2.1-SNAPSHOT.pom
13:52:01.014 [ERROR] [org.gradle.BuildExceptionReporter] file:/C:/Users/William/.m2/repository/org/easyrules/easyrules/2.2.1-SNAPSHOT/easyrules-2.2.1-SNAPSHOT.jar
13:52:01.026 [ERROR] [org.gradle.BuildExceptionReporter] https://repo1.maven.org/maven2/org/easyrules/easyrules/2.2.1-SNAPSHOT/maven-metadata.xml
13:52:01.038 [ERROR] [org.gradle.BuildExceptionReporter] https://repo1.maven.org/maven2/org/easyrules/easyrules/2.2.1-SNAPSHOT/easyrules-2.2.1-SNAPSHOT.pom
13:52:01.049 [ERROR] [org.gradle.BuildExceptionReporter] https://repo1.maven.org/maven2/org/easyrules/easyrules/2.2.1-SNAPSHOT/easyrules-2.2.1-SNAPSHOT.jar
13:52:01.060 [ERROR] [org.gradle.BuildExceptionReporter]
13:52:01.069 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
13:52:01.079 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
13:52:01.095 [LIFECYCLE] [org.gradle.BuildResultLogger]
13:52:01.105 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
13:52:01.116 [LIFECYCLE] [org.gradle.BuildResultLogger]
13:52:01.126 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 15.586 secs

my build.gradle has this

repositories {
mavenLocal()
mavenCentral()
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, ‘seconds’
}

dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11’
compile 'org.easyrules:easyrules-core:2.2.1-SNAPSHOT’
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.11’
}

it makes no difference if I reverse the order of the repositories. I have no .m2/settings.xml defined.

The required POM and Jar from the mvn install are all in the repository and look fine (so far as i can tell)

it fails to resolve this dependency locally. I’m running gradle 2.10

so how is this supposed to work ?

um weird - i just went back and did the mvn build for easyrules again using - “mvn clean install”.

i went back into my project directory and re ran the gradle build with --debug by hand and not via the intellij ide. This time it said it completed successfully. Then when i refresh the gradle script in the ide this time it all resolved ok.

so now it works - i dont know what ‘cleared’ in this process but it now seems to have located the dependency correctly. So weird.

C’est la vie - thats the world of configuration management for you. however its now resolving correctly.

Perhaps something went wrong when installing to maven local the first time. This makes me thing perhaps the POM was corrupt in some way.

Could not parse POM file:/C:/Users/William/.m2/repository/org/easyrules/easyrules-core/2.2.1-SNAPSHOT/easyrules-core-2.2.1-SNAPSHOT.pom

Anyhow, glad to hear your issue is resolved.