Nexus proxy repo not used by Gradle builds? - gradle

I set up an internal Nexus v3.28.x repo, and it's caching artifacts through the proxy repositories that I setup. However, I still see this even though I set up a Maven proxy repo for it, with the remote (source) URL set to https://repo.maven.apache.org/maven2/, and it's status is "Online - Remote available"
Download https://repo.maven.apache.org/maven2/regexp/regexp/1.2/regexp-1.2.jar
Download https://repo.maven.apache.org/maven2/com/jcraft/jsch/0.1.54/jsch-0.1.54.jar
Download https://repo.maven.apache.org/maven2/com/jcraft/jzlib/1.1.1/jzlib-1.1.1.jar
Download https://repo.maven.apache.org/maven2/io/rest-assured/spring-commons/3.2.0/spring-commons-3.2.0.jar
...
(more artifacts from external repo)
I setup my build.gradle files to ONLY access our internal Nexus repo, like this
buildscript {
apply plugin: 'jacoco'
repositories {
mavenLocal()
maven {
url "https://nexus.company.com/"
credentials {
username nexusUser
password nexusPW
}
}
}
dependencies {
classpath "..."
}
}
allprojects {
apply plugin: 'jacoco'
repositories {
mavenLocal()
maven {
url "https://nexus.company.com"
credentials {
username nexusUser
password nexusPW
}
}
}
}
Why is Gradle not downloading from our internal repo?

Related

Is it possible to serve top-level buildscript dependencies using Artifactory?

Here is a sample top-level build.gradle configured with Artifactory:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:x.x.x"
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
apply plugin: 'com.jfrog.artifactory'
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
//... standard artifactory plugin auto-generated from web interface
}
I would like com.android.tools.build:gradle:x.x.x and to be served from an Artifactory remote, rather than from jcenter or the Google Maven Repository since these are blocked by a hostile workplace proxy.
However, it seems that the artifactory Gradle plugin is only available after the buildscript closure has been applied. How can I get the other buildscript dependencies to be served from Artifactory?
You can make simple Maven remote repositories to serve the buildscript dependencies. Since these remote repositories simply mirror the public repositories, you can make the access anonymous. This means that at the time for executing the buildscript closure, there is no need for configuring artifactory_user and artifactory_contextUrl.
A sample build.gradle would look something like this:
buildscript {
repositories {
maven {
url "http:///example.com:8082/artifactory/list/jcenter/"
}
maven {
url "http://example.com:8082/artifactory/list/google-remote/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:x.x.x"
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
where google-remote is the name (repository key) of the remote repository mirroring the Google Maven Repository you have configured yourself.
As for configuring the Artifactory remote for the Google Maven Repository itself, the address is simply maven.google.com as per the picture below:

Gradle maven-publish - custom local maven repository location

I am using:
apply plugin: "maven-publish"
I am trying to install my artifact in $buildDir/repo instead of ~/.m2/repository.
I have tried this:
publishing {
repositories {
maven {
url "$buildDir/repo"
}
}
}
and this:
-Dmvn.repo.local=build/repo
But those are ignored.
I would like to avoid using the settings.xml to set that, is it possible?

gradle archiva integration copy jar from build to archiva repository

I am integrating gradle to archiva.I was able to build the jar of the project successfully , but craeting inside build/libs.
I want to add this jar to my archiva repository internal after build. please guide me
my archiva repo
http://localhost:8080/repository/internal/
See Gradle docs:
Chapter 34. Maven Publishing - describes how to use 'maven-publish' gradle plugin to define publications and repositories.
34.4. Performing a publish - contains full example of additions to build.gradle:
apply plugin: 'java'
apply plugin: 'maven-publish'
group = 'org.gradle.sample'
version = '1.0'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
publishing {
repositories {
maven {
url "http://localhost:8080/repository/internal/"
credentials {
username repoUser
password repoPassword
}
}
}
}
Add credentials {} section if you need to supply username/password for repository. repoUser and repoPassword are variables defined somewhere else. For example, apply gradle-properties-plugin and define these variables in gradle-local.properties:
repoUser=jsmith
repoPassword=secret
Make sure not to commit this file into source code repository.

Unable to publish artifacts to Nexus maven repository using Gradle

I am new to Gradle, nexus and Maven and trying to use Gradle 'publish' task to publish maven artifacts from Jenkins to a new nexus repository. The Jenkins job is failing with below error while publishing. I have provided the user name and password for Nexus in the job.
:common-test:publishMavenJavaPublicationToMavenRepositoryCould not find metadata
com.xx.audit:common-test:1.0.3-SNAPSHOT/maven-metadata.xml in
remote (https://nexus.xx.com:8443/content/repositories/snapshots)
Upload https://nexus.xx.com:8443/content/repositories/snapshots/yy/audit/common-test/1.0.3-SNAPSHOT/common-test-1.0.3-20151102.120123-1.jar
Could not transfer artifact com.xx.audit:common-test:jar:1.0.3-20151102.120123-1
from/to remote (https://nexus.xx.com:8443/content/repositories/snapshots):
Could not write to resource 'yy/audit/common-test/1.0.3-SNAPSHOT/common-test-1.0.3-20151102.120123-1.jar'
Do we need to create folder structure in nexus maven repository before publishing first time? And add the maven-metadata.xml? How are the *.pom.sha, *.pom.md5 are generated.
Please help me on this.
build.gradle configuration:
apply plugin: "maven-publish"
//* New Gradle task to jar source
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
//* New Gradle task to jar javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar {
classifier "sources"
}
}
}
}
publishing {
repositories {
maven {
credentials {
username nexusUsername
password nexusPassword
}
if (project.version.endsWith('-SNAPSHOT')) {
url nexusSnapshotRepoURL
} else {
url nexusReleaseRepoURL
}
}
}
}
I do not know the maven-publish Gradle plugin. Typically the uploadArchives task is used. A full example for its usage is available in the Nexus book examples project. Use that as a reference to test your credentials and setup.

How to access local repo from gradle

I am trying to build a Java project using Gradle. I have some dependencies (jars) that are in a location of the type: http://internal_domain.location.local:9000/artifacts/repo
How do I specify this in the build.gradle file? Is it under repositories {}?
In the gradle documentation I came across this but doing something similar does not work for me:
repositories {
ivy {
url "http://repo.mycompany.com/repo"
resolve.dynamicMode = true
}
}
Assuming your local repo is a maven repo
repositories {
maven {
// Look for POMs and artifacts, such as JARs, here
url "http://repo2.mycompany.com/maven2"
// Look for artifacts here if not found at the above location
artifactUrls "http://repo.mycompany.com/jars"
artifactUrls "http://repo.mycompany.com/jars2"
}
}
Local Archive Gradle

Resources