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
Related
I would like to use snapshot repository for open API generator in Gradle. However it still cannot find the plugin.
settings.gradle.kts
pluginManagement {
repositories {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openapi.generator") version "6.3.0-SNAPSHOT"
}
Error:
Plugin [id: 'org.openapi.generator', version: '6.3.0-SNAPSHOT'] was not found in any of the following sources:
It seems like it is still pointing to the gradle plugin portal.
The URL of the snapshot is
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-gradle-plugin/6.3.0-SNAPSHOT
You need to update groupId (org.openapitools) and artifactid (openapi-generator-gradle-plugin)
Using 5.4.1, Gradle was able to resolve dependencies of the form:
dependencies {
implementation "my.groupname:my-project-name:${version}"
}
where the dependency artifacts were stored in jFrog artifactory under:
//my.artifactory.url/my-repo/my.groupname/my-project-name/
If I upgrade my wrapper to 6.5, Gradle isn't able to resolve the dependencies any longer. If the setup were completely under my control, I'd move the artifacts to:
//my.artifactory.url/my-repo/my/groupname/my-project-name/
and be on my merry way. Unfortunately, it's not, so I can't. Is there a straightforward way to workaround it in my project without changing the structure in artifactory? I'm using maven dependency resolution, as well as the id com.jfrog.artifactory plugin at version 4.16.0.
Updated: (The original answer only worked on a hot cache) I was able to resolve the issue by adding an entry to the repositories and also hacking the dependencies a bit section of build.gradle:
repositories {
// ... other repositories
maven {
url "my.artifactory.url/my-repo/"
artifactUrls "my.artifactory.url/my-repo/my.groupname"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
metadataSources {
artifact()
ignoreGradleMetadataRedirection()
}
}
}
dependencies {
implementation ".:my-project-name:${version}"
}
Initially, I had also included mavenPom() in the metadataSources, but there was an incorrect pom.xml on the other end, so I had to remove it (the groupId in pom.xml was missing).
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()
}
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:
In my project i want to copy certain artifact (war file) from maven repo to local folder in order to deploy. I tried using configurations object but i couldn't give specific groupid, artifact id, and version in that way
repositories {
mavenCentral() // or some other repo
}
configurations {
deploy
}
dependencies {
deploy "someGroup:someArtifact:someVersion"
}
task copyDeploy(type: Copy) {
from configurations.deploy
into "deploy"
}
You can find all of this and more in the Gradle User Guide (e.g. under "Working with dependencies") and the many samples in the full Gradle distribution.