My project use 1 remote maven repository and 1 local maven repository.
The artifact I need only exists in the local maven repository.
apply plugin: 'maven'
repositories {
mavenLocal()
maven {
url "https://dev.idondemand.com/nexus/content/groups/idod-proxy"
credentials {
username System.properties['NEXUS_USER']
password System.properties['NEXUS_PASSWORD']
}
}
}
<dependencies>
compile "com.idondemand:idondemandservice:0.0.1-SNAPSHOT:renderedbadge@zip"
<dependencies>
Now the gradle always throws exception to inform that “Could not find that artifact”. (not be the same as I work with Maven)
Other problem is that if both repositories contains artifact A, I need gradle will get the newest artifact A. Now it seems that gradle always get from the remote repository. (not be the same as I work with Maven)
From the information you provide, I can’t tell what the problem is. Usually, Gradle should certainly find the artifact in the local repository.
As for the other question, Gradle will query the repositories in the order they are declared, and I’m not aware of a way to get the newer snapshot of either repository. I agree that this can be useful though. Maybe someone else can confirm whether this limitation exists.
Maybe someone else can confirm whether this limitation exists.
That is the case as of today.
Hi all,
I can make sure that the GRADLE (1.1) only works with the FIRST maven repository although I declare 2 repositories (local and remote).
You can’t. Only declare one repository then. You can use an if-statement to declare repositories conditionally.
Do you mean that the code I wrote above is redundant ? That remote repository won’t work.
I thought that GRADLE works with both repositories. It get artifacts from local repo first. If not exist in local repo, it will get from remote repo.
Yes, that’s correct. But I thought you asked how to make sure that Gradle only uses the first repository. If the remote repo doesn’t work, it’s probably misconfigured. Of course it would help if you provided more information. Exact error message, full stack trace (-s), etc. Also there is some XML in your code snippet. Not sure what’s that supposed to mean.
Hi Peter,
I’m moving from Maven to Gralde for Java project now :).
Currently, I have some native controls ( in C language) still be built with Maven so when develop Java project with Gradle, we want to use those native artifacts from mavenLocal instead of remote repository (C code be built with Maven will be installed to mavenLocal when developing) but some other artifacts we need to get from remote repository (because mavenLocal still not have those).
You can imagine with what Maven do. (get from local repo, if not then get from remote repo).
Thanks, Phuong.
I don’t see why this wouldn’t work with Gradle.
Hi Peter,
Assume that my MavenLocal has artifact A, MavenRemote has artifact B. My project need both artifacts.
How can I do with Gradle for my project ?
Thanks,
repositories { maven { … }; mavenLocal() }
Hi Peter,
I have tested as you suggested but Gradle cannot resolve the dependency A (of MavenLocal). It throws the error message: “Artifact A not found”
Thanks, Phuong.
Try with ‘–refresh-dependencies’. Running with info (’-i’) or debug (’-d’) logging will give you more information. Usually this works just fine, so there must be something special about your situation.
Hi Peter,
Could you please see some log below?
As I see, Gradle don’t request any resources from MavenLocal although it cannot get those resourses from MavenRemote.
Thanks,
[SUCCESSFUL ] org.bouncycastle#bcprov-ext-jdk16;1.46!bcprov-ext-jdk16.jar (536ms) Cached resource is up-to-date (lastModified: Wed Feb 23 11:04:14 ICT 2011). [HTTP: https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/bouncycastle/bcprov-jdk16/1.46/bcprov-jdk16-1.46.jar] downloading CachedResource: C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.bouncycastle\bcprov-jdk16\1.46\jar\ce091790943599535cbb4de8ede84535b0c1260c\bcprov-jdk16-1.46.jar for https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/bouncycastle/bcprov-jdk16/1.46/bcprov-jdk16-1.46.jar …
[SUCCESSFUL ] org.bouncycastle#bcprov-jdk16;1.46!bcprov-jdk16.jar (546ms) Cached resource is up-to-date (lastModified: Mon Feb 27 17:34:43 ICT 2012). [HTTP: https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/bouncycastle/bcmail-jdk16/1.46/bcmail-jdk16-1.46.jar] downloading CachedResource: C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.bouncycastle\bcmail-jdk16\1.46\jar\8a9233bfd6ad38ea32df5e6ff91035b650584b9\bcmail-jdk16-1.46.jar for https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/bouncycastle/bcmail-jdk16/1.46/bcmail-jdk16-1.46.jar …
[SUCCESSFUL ] org.bouncycastle#bcmail-jdk16;1.46!bcmail-jdk16.jar (455ms) Cached resource is up-to-date (lastModified: Wed Apr 18 02:08:45 ICT 2012). [HTTP: https://dev.idondemand.com/nexus/content/groups/idod-proxy/net/sf/ehcache/ehcache-core/2.5.2/ehcache-core-2.5.2.jar] downloading CachedResource: C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\net.sf.ehcache\ehcache-core\2.5.2\jar\31cbafefbecb34a1081939230a5bc6f13a1c55db\ehcache-core-2.5.2.jar for https://dev.idondemand.com/nexus/content/groups/idod-proxy/net/sf/ehcache/ehcache-core/2.5.2/ehcache-core-2.5.2.jar …
[SUCCESSFUL ] net.sf.ehcache#ehcache-core;2.5.2!ehcache-core.jar (522ms) Resource missing. [HTTP HEAD: https://dev.idondemand.com/nexus/content/groups/idod-proxy/com/idondemand/idondemandservice/0.0.1-SNAPSHOT/idondemandservice-0.0.1-SNAPSHOT-renderedbadge.zip]
FAILURE: Build failed with an exception.
-
What went wrong: Could not resolve all dependencies for configuration ‘:util:compile’. > Artifact ‘com.idondemand:idondemandservice:0.0.1-SNAPSHOT:renderedbadge@zip’ not found.
-
Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 37.095 secs
What happens if you use ‘maven { url “file:///…” }’ instead of ‘mavenLocal()’ to declare the local repository?
Ok. Let me try but to be honest that I don’t know how to use URL to declare MavenLocal instead :).
Just a regular file URL that points to your local Maven repo. If your local repo is in the default location, you can create the URL with ‘new File(System.getProperty(“user.home”), “.m2/repository”).toURI().toURL()’. Also double check that the snapshot dependency is actually contained in that repo.
Same result :(.
OK, let me try later with a small example. Thank you very much for many answers from you
Hi Peter,
I have tried with
repositories { maven { url localMavenUrl}; maven {url remoteMavenUrl} }
And it works well :D.
You can see the log below.
Thank you very much, Peter!
Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/commons-codec/commons-codec/1.4/commons-codec-1.4.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\commons-codec\commons-codec\1.4\jar\4216af16d38465bbab0f3dff8efa14204f7a399a\commons-codec-1.4.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\commons-lang\commons-lang\2.6\jar\ce1edb914c94ebc388f086c6827e8bdeec71ac2\commons-lang-2.6.jar] Cached resource is up-to-date (lastModified: Tue May 22 13:01:31 ICT 2012). [HTTP: https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/apache/ant/ant/1.8.4/ant-1.8.4.jar] downloading CachedResource: C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.apache.ant\ant\1.8.4\jar\8acff3fb57e74bc062d4675d9dcfaffa0d524972\ant-1.8.4.jar for https://dev.idondemand.com/nexus/content/groups/idod-proxy/org/apache/ant/ant/1.8.4/ant-1.8.4.jar …
[SUCCESSFUL ] org.apache.ant#ant;1.8.4!ant.jar (535ms) Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/junit/junit/4.8.2/junit-4.8.2.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\junit\junit\4.8.2\jar\c94f54227b08100974c36170dcb53329435fe5ad\junit-4.8.2.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/com/google/inject/guice/2.0/guice-2.0.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\com.google.inject\guice\2.0\jar\a4c67006178262122e93121e94fff306fcf0cda1\guice-2.0.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/com/google/inject/extensions/guice-multibindings/2.0/guice-multibindings-2.0.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\com.google.inject.extensions\guice-multibindings\2.0\jar\bfa4c1036fd7dc58019d0aeaec3faf4e8a685474\guice-multibindings-2.0.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/org/jasypt/jasypt/1.6/jasypt-1.6.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.jasypt\jasypt\1.6\jar\1550a512e10a517a557254f15a12392393245610\jasypt-1.6.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/org/bouncycastle/bcprov-ext-jdk16/1.46/bcprov-ext-jdk16-1.46.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.bouncycastle\bcprov-ext-jdk16\1.46\jar\f8b715ea4b72f9fc67062e9f1c056914d40b728a\bcprov-ext-jdk16-1.46.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/org/bouncycastle/bcprov-jdk16/1.46/bcprov-jdk16-1.46.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.bouncycastle\bcprov-jdk16\1.46\jar\ce091790943599535cbb4de8ede84535b0c1260c\bcprov-jdk16-1.46.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/org/bouncycastle/bcmail-jdk16/1.46/bcmail-jdk16-1.46.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\org.bouncycastle\bcmail-jdk16\1.46\jar\8a9233bfd6ad38ea32df5e6ff91035b650584b9\bcmail-jdk16-1.46.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/net/sf/ehcache/ehcache-core/2.5.2/ehcache-core-2.5.2.jar, C:\Users\phuonglu.gradle\caches\artifacts-14\filestore\net.sf.ehcache\ehcache-core\2.5.2\jar\31cbafefbecb34a1081939230a5bc6f13a1c55db\ehcache-core-2.5.2.jar] Found locally available resource with matching checksum: [C:\Users\phuonglu.m2\repository/com/idondemand/idondemandservice/0.0.1-SNAPSHOT/idondemandservice-0.0.1-SNAPSHOT-renderedbadge.zip, C:\Users\phuonglu.m2\repository\com\idondemand\idondemandservice\0.0.1-SNAPSHOT\idondemandservice-0.0.1-SNAPSHOT-renderedbadge.zip]