multiple maven repositories for gradle - maven

If I have multiple maven repositories specified in a gradle build, I am expecting that if gradle cannot find a dependency in one of the repositories it should just try the other ones. Instead, it fails on the first repository (internal company nexus repo) for a dependency that does not exists there and fails the build
repositories {
maven {
url = 'http://mavencentral.it.att.com:8084/nexus/content/groups/att-public-group'
}
mavenLocal()
mavenCentral()
maven { url 'http://maven.springframework.org/milestone/' }
}
FAILURE: Build failed with an exception.
* What went wrong: Could not resolve all dependencies for configuration ':metadata-security:compile'.
> Artifact
'spring-security-kerberos-core.jar
(org.springframework.security.extensions:spring-security-kerberos-core:1.0.0.M2)'
not found. Searched in the following locations:
http://mavencentral.it.att.com:8084/nexus/content/groups/att-public-group/
org/springframework/security/extensions/spring-security-kerberos-core/1.0.0.M2/spring-security-kerberos-core-1.0.0.M2.jar

As said by #Mark Viera in the comments:
Try running the build with --debug. It likely means that Gradle found
a descriptor (pom.xml) but not the artifact itself.
That is, it was missing the jar file (as confirmed by the OP).

Related

Gradle Nexus and FlatDir deployment without java-, ear- or war-plugin

I have a multi-project gradle (version 2.1!!) build consisting of non-java projects.
I would like to deploy the generated artifacts (.tar.gz files) to a Nexus and also to a directory.
Currently I define the repositories in the root build.gradle in the repositories block and also again for each sub-project in a repositories block inside the subprojects in the root build.gradle file.
I apply the base plugin to the root project and the maven-publish plugin to all subprojects that have artifacts to be deployed.
I tried to follow the instructions here:
https://docs.gradle.org/2.1/userguide/publishing_maven.html
https://docs.gradle.org/2.1/dsl/org.gradle.api.publish.maven.MavenPublication.html
https://discuss.gradle.org/t/how-to-have-multiple-uploadarchives/19381/3
How can I make uploadArchives dependent on another task?
and a few more...
but nothing worked. :-(
Here's what I do:
...
# apply the maven-publish plugin only to sub-projects that produce artifacts that should be uploaded.
apply plugin: 'maven-publish'
publishing {
publications {
tarFiles (MavenPublication) {
artifact compressTar
}
}
repositories {
add rootProject.repositories.fsShare
add rootProject.repositories.nexusDeploy
}
}
...
The compressTar is my custom Tar task that creates the artifacts that I want to upload.
When I execute ./gradlew publishTarFilesPublicationToNexusDeployRepository I get the following error:
Execution failed for task ':mySubProject:publishTarFilesPublicationToNexusDeployRepository'.
> Failed to publish publication 'tarFiles' to repository 'nexusDeploy'
> Failed to retrieve remote metadata myRootProject:mySubProject:0.0.0.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata myRootProject:mySubProject:0.0.0.0-SNAPSHOT/maven-metadata.xml from/to remote (https://myProject.nexus.url:443/nexus3/repository/builds/): Could not get resource 'myRootProject/mySubProject/0.0.0.0-SNAPSHOT/maven-metadata.xml'
When I execute uploadArchives, the task succeeds, but nothing is uploaded anywhere and from the output it looks like the uploadArchives task is only executed for sub-projects that didn't get the maven-plugin applied.
What is the right way to do this? Which plugins should I apply when/where?
Apparently there were two un-related "problems at work" here.
Problem 1): I was not able to publish to Nexus and got a Failed to retrieve remote metadata-error:
Answer 1): I was trying to publish a "SNAPSHOT" to a repository that was configured not to accept "SNAPSHOT" build. Renaming the build version from 1.2.3.4-SNAPSHOT to anything else (e.g. 1.2.3.4-SNAPSHOT-dev or more reasonable 1.2.3.build4`) worked fine.
Problem 2) Publishing to 'flatDir' repository didn't work. The maven-publish plugin didn't create the publish task for it.
Answer 2) To use maven-publish to publish to a directory, flatDir apparently is not recognized as repository the maven-publish plugin can publish to. Defining the 'directory' repository as follows worked fine:
maven {
name "fsShare"
url "/share/pkg"
}

Gradle cannot resolve dependencies for Sonar-Runner

I am trying to set up the Sonar-Runner with my existing gradle project. I am using Sonar-Runner 2.4 Gradle 2.2.1 and our Sonar server is 4.3.1. When I run gradle sonarRunner I get the following error:
Could not resolve all dependencies for configuration ':sonarRunner'.
Cannot resolve external dependency org.codehaus.sonar.runner:sonar-runner-dist:2.4 because no repositories are defined.
I do have the artifact "org.codehaus.sonar.runner:sonar-runner-dist:2.4" in my nexus server that is set up in my build.gradle file. Does anyone have any intuition about this error? I have googled it extensively and been stuck on this for a couple of hours now.
My build.gradle for the sonar runner is very simple:
apply plugin: 'sonar-runner"
sonarRunner{
toolVersion = '2.4'
sonarProperties{
property "sonar.host.url", "$sonarHost"
}
}
It seems no repository is declared for the project you want to use with the sonar-runner plugin.
You might have configured repositories for buildscript or for other projects only (in your multiproject build?)
To resolve the sonar-runner you need to configure a repository where it could be resolved from. You might have a coorporate repository in your company or you could use public ones like mavencentral or bintray. to declare for example the jcenter repository to resolve the sonar-runner. just add the following to your build script:
repositories {
jcenter()
}

Dependenciies in Gradle not working correctly

We have a project that is using Java 1.5 and we are trying to convert from Maven to Gradle.
We have a repository that is local to us containing all the versions of all the jars we need as the dev environment has no access to the internet.
The problem we are seeing is that it cannot find the commons-io jar and keeps trying to goto the external maven repo. we have not even set that up so where is it finding it from?
we have repositories and dependencies set up in the All projects section as follows
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.5
targetCompatibility = 1.5
project.tasks.withType(AbstractCompile, { AbstractCompile ac -> ac.options.bootClasspath = "C:/Program Files/java/1.5.0_14/jre/lib/rt.jar" })
repositories {
mavenLocal()
maven { url "http://internalrepo/maven-local" }
}
dependencies {
compile "org.apache.commons:commons-io:1.3.2"
}
But its reporting
Could not resolve org.apache.commons:commons-io:1.3.2.
inconsistent module metadata found
even though it works fine in Maven using mvn install
Gradle will never query a repo that isn't set up. mavenlocal() is misspelled (should be mavenLocal()), which will make the build fail. "Inconsistent metadata" could mean that the group ID, artifact ID, or version in the POM doesn't match the one in the build script. mavenLocal() should only be used if the Gradle build needs to exchange artifacts with local Maven builds.
Found the issue,
Unbeknownst to me there was a hidden repo in the maven settings.xml in the maven install folder.
Adding that resolved the issue.

Grails and Sesame

I'm trying to import core libraries of OpenRDF Sesame into a Grails Application.
This is an extract of my BuildConfig.groovy file:
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
}
dependencies {
compile 'org.openrdf.sesame:sesame-core:2.7.7'
}
I get this error message:
Error Could not find artifact org.openrdf.sesame:sesame-core:jar:2.7.7 in grailsCentral (http://repo.grails.org/grails/plugins) (scope: runtime) (Use --stacktrace to see the full trace)
I can't figure out how to solve this issue, the artifact is available on Maven Central:
http://search.maven.org/#artifactdetails%7Corg.openrdf.sesame%7Csesame-core%7C2.7.7%7Cpom
There's no jar there, just a POM file, and it has no dependencies: http://repo1.maven.org/maven2/org/openrdf/sesame/sesame-core/2.7.7/
Looks like you're going to need to specify the individual jar dependencies that you need - e.g. http://repo1.maven.org/maven2/org/openrdf/sesame/sesame-http-client/2.7.7/

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