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

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:

Related

Nexus proxy repo not used by Gradle builds?

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?

Gradle can't find dependency in private nexus repo

I'm having trouble getting gradle to find a dependency I put in my private nexus repo. The dependency is in maven, but I can't seem to get it to find it there either. I did get it into my nexus repo and the location is http://nexus.hq.chris.com/content/repositories/emoji4j/
Could not resolve all dependencies for configuration ':business:compile'.
> Could not find com.kcthota:emoji4j:6.0.
Searched in the following locations:
http://nexus.hq.chris.com/content/groups/public/com/kcthota/emoji4j/6.0/emoji4j-6.0.pom
http://nexus.hq.chris.com/content/groups/public/com/kcthota/emoji4j/6.0/emoji4j-6.0.jar
file:/Users/chris/.m2/repository/com/kcthota/emoji4j/6.0/emoji4j-6.0.pom
file:/Users/chris/.m2/repository/com/kcthota/emoji4j/6.0/emoji4j-6.0.jar
Required by:
Build.gradle snipet
dependencies {
// https://mvnrepository.com/artifact/com.kcthota/emoji4j
compile group: 'com.kcthota', name: 'emoji4j', version: '6.0'
}
buildscript {
repositories {
maven {
url "http://nexus.hq.chris.com/content/groups/public/"
}
maven { url "https://repo1.maven.org/maven2/" }
maven { url "http://nexus.hq.chris.com/content/repositories/emoji4j/" }
mavenCentral()
}
dependencies {
classpath 'com.jcraft:jsch:0.1.54'
}
}
Anyone know how I can get gradle to look in both http://nexus.hq.chris.com/content/groups/public/ and http://nexus.hq.chris.com/content/repositories/emoji4j/ for all my dependencies? I need the http://nexus.hq.chris.com/content/groups/public/ location for other dependencies. I tried adding it in there but I only have read access to that repo.
Another acceptable solution would be to get gradle to look in both http://nexus.hq.chris.com/content/groups/public/ and maven central for it. Any help would be appreciated.
I think you may be confusing dependencies for your build script and application dependencies.
You've configured your build script repositories, but you'll need to also configure your application repositories as well:
// build.gradle
repositories {
maven {
url "http://nexus.hq.chris.com/content/groups/public/"
}
maven { url "https://repo1.maven.org/maven2/" }
maven { url "http://nexus.hq.chris.com/content/repositories/emoji4j/" }
mavenCentral()
}

Gradle: Configure Repository for transitive dependencies

imagine you have to go through proxy repositories for all dependency resolutions, because you are behind a proxy.
For most repositories, this can be easily configured within the build.gradle file:
buildscript {
repositories { ... }
}
and
repositories { ... }
and even in settings.gradle the
pluginManagement {
repositories { ... }
}
but it seems that transitive dependencies are still downloaded through jCenter.
Where can I configure the repositories for transitive dependencies?
Update: I still try to find the real root cause of my problem. It could be that it has to do with the way I've build my build script - the dependencies are defined in a script plugin of a sub project.
I still don't know why my system behaves this way, but here is a solution which works for me:
create a file called init.gradle in USER_HOME/.gradle/ and add your repositiories like this:
allprojects {
buildscript {
repositories { ... }
}
repositories { ... }
}

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

Gradle custom plugin dependencies

If a have a custom plugin which handles the building and deploying of a specific component, where do I list the dependencies (other components in my system) which are required for the build?
Dependencies for your Gradle plugins should be listed in the buildscript portion of the build.gradle file. See this chapter of the User Guide, which also has an example:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:0.4.1"
}
}
apply plugin: "com.jfrog.bintray"
If your custom plugin depends on jar files on your local machine, I gather that you need to add those files as a "flatDir" repository in the repositories entry, as described here:
repositories {
flatDir {
dirs 'lib1', 'lib2'
}
}

Resources