Gradle can't find dependency in private nexus repo - gradle

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()
}

Related

Could not find com.github.everit-org.json-schema:org.everit.json.schema

I'm trying to add the below dep in my build.gradle and added the below repos but it's still not able to download the dep.
repositories {
maven {
url 'http://packages.confluent.io/maven/'
}
maven {
url "https://repository.mulesoft.org/nexus/content/repositories/public/"
}
maven { url 'https://jitpack.io' }
jcenter()
mavenCentral()
mavenLocal()
}
Below is the error I'm getting:
> Could not find com.github.everit-org.json-schema:org.everit.json.schema:.
Required by:
project :<my-project-module-name>
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
its my mistake, I've added an extra colon while defining the gradle dependencies..So, it worked after removing it.

Could not resolve: org.jetbrains.pty4j:pty4j:0.9.8

In my build.gradle file.
repositories {
maven {
url "https://jetbrains.bintray.com/pty4j"
}
mavenCentral()
}
dependencies {
implementation group: 'org.jetbrains.pty4j', name: 'pty4j', version: '0.9.8'
}
If I build my project it comes like this
Could not resolve org.jetbrains.pty4j:pty4j:0.9.8.
Possible solution:
- Declare repository providing the artifact, see the documentation at
https://docs.gradle.org/current/userguide/declaring_repositories.html
screen shot
How can I solve this error ?
That particular artefact is not provided by MavenCentral() but rather by the Spring Release Repository. One useful trick to find out which repositories provide a given artefact is to seek your artefact here and pay attention to the repositories link provided.
You'll need then to change your Gradle config to something like:
repositories {
mavenCentral()
maven { url "https://packages.jetbrains.team/maven/p/ij/intellij-dependencies" }
}

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

Is it possible to restrict a gradle repository to a particular configuration?

I want to tie gradle repositories to specific configurations in my build.gradle file, e.g.:
repositories {
testCompile {
mavenCentral()
}
compile {
maven { url 'https://vetted-repo.example.com' }
}
}
I can't find a simple way to do this from the gradle documentation. Do I need to write my own plugin?
As of Gradle 5.1 this is now possible, from the release notes:
It is now possible to match repositories to dependencies, so that
Gradle doesn't search for a dependency in a repository if it's never
going to be found there.
Example:
repositories {
maven {
url "https://repo.mycompany.com"
content {
includeGroupByRegex "com\\.mycompany.*"
}
}
}
For the specific requirement of restricting a repository to a specific configuration such as compile, you could use the onlyForConfigurations property:
repositories {
maven {
url "https://vetted-repo.example.com"
content {
onlyForConfigurations "compile"
}
}
}
This is not supported by gradle at the moment. When resolving dependencies, gradle tries al listed repositories (from top to bottom) to resolve a dependency. Once the dependency is found it stops looking for it in other repositories
It is now possible to declare a repository filter in gradle. see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_a_repository_filter this does exactly what you need here.

Resources