use gradle to download ivy jar, but the jar name is wrong - gradle

I use gradle to download the ivy jars, gradle script like this:
repositories {
ivy {
artifactPattern "http://mycompany/libs/[organization]/[module]/[revision]/[artifact].[ext]"
ivyPattern "http://mycompany/libs/[organization]/[module]/[revision]/ivy.xml"
}
}
dependencies {
compile (
"org.slf4j:slf4j-api:1.6.4"
)
}
and My ivy config like this:
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.4">
<artifact name="slf4j-api-1.6.4" type="jar"/>
</dependency>
the jar name on the ivy respository is :
http://my.company/his-libs/org.slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4.jar
but when I download them use gradle, the jar'name is :
D:\Users\myname.gradle\caches\artifacts-23\filestore\org.slf4j\slf4j-api\1.6.4\jar\bff73780230e6559b63134bbc2056c312eabb849\slf4j-api-1.6.4-1.6.4.jar
increase "-1.6.4" in the jar name. Can anybody help? Thanks.

Your Ivy config has the version number in the artifact name. Gradle's dependency cache isn't Ivy based and will always construct the file name from the artifact name and version. You can't change this but can change the file name when, say, copying or packaging the artifact file.

Related

Gradle: How do I copy POM files to WAR?

The WEB-INF\lib folder in our WAR file should serve as a flatDir repository for our users. I presume I need to supply a POM file for each JAR, so that transitive dependencies would be resolved.
How do I copy POM files for each JAR to WEB-INF\lib folder in my WAR file?
My root project script:
apply plugin: 'war'
jar.enabled = false
war {
dependencies {
subprojects.each { runtime it }
providedCompile servlet
}
}
Please see the flatDir documentation which states
Note that this type of repository does not support any meta-data formats like Ivy XML or Maven POM files.
If you want to download all dependencies (and pom files) to a maven directory structure you can use this gist. To download javadocs and sources too see this answer

Gradle get dependency from pom file

How can get dependency from pom file. Also pom file has repositories tag So i also need to use that repository if dependency not found in mavenCentral()
How can i do this????

Gradle Dependency loading from maven

I am new to gradle.
I have seen some examples about java dependency like the following example but my project will be simply a zip file.
I just want to download the zip file.
apply plugin: 'java'
dependencies {
compile 'commons-lang:commons-lang:2.6'
}
In the above example, it will automatically download the jar file. But it doesn't download my zip file if my maven repositories contains zip that mentioned in the pom.xml about that package.
Questions:
What is the flow when depend on a maven repository? It will first read the pom.xml and then download the zip file?
How to dynamically load the dependency? e.g 'commons-lang:commons-lang:2.6' will have dependency of 'commons-lang:en:1.0" in the pom.xml. How to make it automatically load and loop the dependency list?
Thanks all
I have tried the follwoing script but it gives me error on compile but I have apply the java plugin
My gradle file
apply plugin: 'java'
repositories {
mavenLocal()
maven {
url "http://nexus.com/myrepo/"
}
}
dependencies {
compile 'com.a.b:projectA:2.0#zip'
}
I can run without problem that files downloaded are inside .m2
Question about the transitive dependency
I have the pom.xml like this. But it is unable to load the dependency one. It will directly go to the new pom.xml first or download zip directly if i mention sth like this?
<dependencies>
<dependency>
<groupId>com.a.b.c</groupId>
<artifactId>base</artifactId>
<version>1.2</version>
<type>zip</type>
</dependency>
</dependencies>
When declaring a dependency and a maven repository, this maven repository will be used to resolve the artifact. this means that usually first the metadata is read and then the artifact will be downloaded. If no repository is declared the resolution will fail early.
Having a dependency notation like yours:
dependencies {
compile 'commons-lang:commons-lang:2.6'
}
gradle resolves the default artifact of that dependency. If you want to resolve additional declared zip files from maven central, you have to use this notation
repositories{
mavenCentral()
}
dependencies {
compile 'commons-lang:commons-lang:2.6#zip'
}
As a default, the a dependency is transitive. This means, that if e.g 'commons-lang:commons-lang:2.6' has a dependency on 'commons-lang:en:1.0" in its pom.xml the commons-lang library (and again its transitive dependencies if any) is also resolved.
cheers,
René

How to publish in order to resolve latest.integration with gradle?

What I have is a maven repository (nexus) to which maven has been publishing. In each artifact version folder in my artifact repository folder there are the standard maven artifacts: a maven-metadata.xml, a jar, and a pom.xml, etc.
Now I want to resolve these using gradle. In my gradle.build file if I list them as:
dependencies {
compile group: 'com.company', name: 'artifact', version: '1.0-SNAPSHOT'
}
Then they will resolve correctly. However, I want to use the version "latest.integration" so that I can automatically integrate the latest versions of my dependencies. When I do this though, gradle fails to resolve it.
I imagine that gradle is looking for some ivy specific files that maven is not publishing up to the repository in order to resolve latest.integration, but I am not sure. Should I go back and re-publish all of my upstream dependencies with gradle before trying to resolve down stream? It would seem that since gradle supports maven repositories under the repositories element that it should already know how to interpret "latest.integration" for that repository type.
This is my repositories section:
repositories {
mavenCentral()
maven { url "http://<server>/nexus/content/repositories/snapshots" }
}
Thank you for any help you can provide
latest.integration is an Ivy concept, and only works for Ivy repositories. In other words, both publication and consumption would have to happen in an Ivy-compatible manner. (Gradle is capable of this; not sure about Nexus.)
The obvious alternative is to use Maven snapshot dependencies. What do you hope to gain from using latest.integration?

Gradle way of handling maven non-lib artifact dependencies

I previously archived a zip artifact in our internal Maven repository.
In my Gradle buildscript I can reference the artifact as a dependency and can get a path to the artifact, using:
configurations{
resourceProperties
}
dependencies{
resourceProperties "$group:$name:$version"
}
... def path = configurations.resourceProperties.asPath
Unfortunately I get all the zip artifact's project dependencies appended on the path as well.
Is there another Gradle way to handle non-lib Maven artifacts required in my build?
You can include a file or directory as a dependency.
Try to look at this starting from par 45.4

Resources