I have an issue with how gradle resolves my dependencies.
I have four repositories that I need to investigate for different jars, five counting Maven central. Thus my repo statment in gradle.build looks like this:
repositories {
maven {
url 'urltoRepoA'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoB'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoC'
artifactUrls mavenLocal()
}
maven {
url 'urltoRepoD'
artifactUrls mavenLocal()
}
mavenCentral()
}
What I want to acheive:
Look for dependencies both in the remote repositories and the local maven repository.
But I get this error below, that is a jar that should be resolved from repoA (repoA is a mirror of maven central, and I have verified that this jar can be found there)
[16:43:10][Step 1/3] > Could not resolve all dependencies for configuration ':runtime'.
[16:43:10][Step 1/3] > Artifact 'junit:junit:4.11#jar' not found.
According to what I've read in gradles manual is that it tries to resolve all the dependencies from the same repo. Is that what I'm running in to here? Or have I failed to configure gradle properly?
I suspect there is something wrong elsewhere in your gradle configuration. I think you are misunderstanding how gradle resolves artifacts.
According to the gradle docs (see section 8.5)
A project can have multiple repositories. Gradle will look for a
dependency in each repository in the order they are specified,
stopping at the first repository that contains the requested module.
In fact, it's rather common to have multiple repositories in a gradle script.
Related
Inherited a project and am trying to run the build.gradle but the dependency is no long on maven... and I have googled and can't find any other active repos. There's a vaadin-spring 1.0.1 but I don't know if that's the same thing. Any body else run into this issue?
buildscript {
repositories {
//jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
classpath('fi.jasoft.plugin.vaadin:fi.jasoft.plugin.vaadin.gradle.plugin:1.0.1')
}
}
apply plugin: "fi.jasoft.plugin.vaadin"
The error:
Could not get resource 'http://dl.bintray.com/johndevs/maven/fi/jasoft/plugin/gradle-vaadin-plugin/1.0.1/gradle-vaadin-plugin-1.0.1.jar'.
> Could not HEAD 'http://dl.bintray.com/johndevs/maven/fi/jasoft/plugin/gradle-vaadin-plugin/1.0.1/gradle-vaadin-plugin-1.0.1.jar'. Received status code 502 from server: Bad Gateway
I tried to do a > build gradle and got the error. I have also tried importing a cache on a teammate that has it working but it does not recognize the cache I have imported by replacing my ~/.gradle with my teammates files
It looks like you've added a dependency on the wrong Maven coordinates.
Looking in the Gradle Plugin Portal I can see that the dependency should be classpath("fi.jasoft.plugin:gradle-vaadin-plugin:1.0.1")
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
// wrong coordinates:
// classpath('fi.jasoft.plugin.vaadin:fi.jasoft.plugin.vaadin.gradle.plugin:1.0.1')
// correct coordinates:
classpath("fi.jasoft.plugin:gradle-vaadin-plugin:1.0.1")
}
}
The coordinates you had used, fi.jasoft.plugin.vaadin:fi.jasoft.plugin.vaadin.gradle.plugin:1.0.1, do actually exist in the Gradle Plugin Portal Maven repo, but there's no JAR. Why is this?
The reason for this is that Gradle plugins require a marker artifact, so that Gradle can identify plugins using an ID in the plugins block DSL.
For this reason, I recommend you replace using the buildscript {} block to define plugins, and instead use the new plugins {} block.
plugins {
id "fi.jasoft.plugin.vaadin" version "1.0.1"
}
I am using one library from github to create a tableview but the tableview is showing an error in my project. I have added their implementation in my gradle file.
Library Link : https://github.com/evrencoskun/TableView
JitPack seems to be published on jcenter whose use is now deprecated in Android. All non-Google artifacts now come from mavenCentral. The solution isn't documented in the official JitPack docs, but we can use the dependencyResolutionManagement block, like,
// settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" }
}
}
rootProject.name = "App"
include ':app'
The code will enforce settings repositories on the repositories mentioned in build.gradle. For repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) the official docs say,
If, for some reason, a project or a plugin declares a repository in a project, Gradle would warn you. You can however make it fail the build if you want to enforce that only settings repositories are used
Refer to this answer along with this one.
Is there any difference between google() and maven { url 'https://maven.google.com' } in build.gradle file and if there is any, what is it?
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
// OR
google()
}
}
The google() repository is a shortcut to Google's maven repository. It was introduced in Gradle 4.x+. The actual repository URL used is `"https://dl.google.com/dl/android/maven2/" as specified here. https://maven.google.com actually points to the same repository.
However, if you are planning to use the google() shortcut, you need Gradle 4.x+, Android Studio 3.x+ and Gradle plugin for Android 3.x+.
Small correction to the answer above.
If you try to go to https://dl.google.com/dl/android/maven2/ it gives you a 404.
The correct url to google maven repository is:
https://dl.google.com/dl/android/maven2/index.html
or just
https://maven.google.com
Here you can check all the supported libraries and the latest versions.
When using gradle, you can mention multiple repositories which the build tool (gradle) uses to resolve dependencies mentioned in your project.
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
}
In the above scenario, you're mentioning 3 repositories which gradle can use to resolve dependencies—all of which are Maven repositories.
1. jcenter()
Means the JCenter Maven repository.
This is a shortcut available in later versions of gradle
2. { url 'https://maven.google.com' }
This means you are referring a Maven repo hosted at the URL which can be used by gradle to resolve the dependencies.
If you want, you can actually enter the URL for JCenter and this would be the same as mentioning jcenter() in the gradle file.
3. google()
This means the Google Maven repository
Similar to the notation maven(), this can be used in later versions of gradle only
Below is my gradle build script:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
apply plugin: 'spring-boot'
apply plugin: 'base'
task wrapper(type: Wrapper) {
gradleVersion = '2.12'
}
repositories {
ivy {
url 'my.url'
}
}
dependencies {
archives group: 'my.group', name: 'artifact.name', version: '16.06.29.5144', configuration: 'dist'
}
In it I try to add one dependency to archives configuration. This is dependency published into Ivy repo and it has several configuration, among them a dist configuration. But it does not have default configuration.
Now, if I run gradlew dependencies I get the following error:
Execution failed for task ':dependencies'.
Could not resolve all dependencies for configuration 'detachedConfiguration4'.
> Module version :gtest:unspecified, configuration 'detachedConfiguration4' declares a dependency on configuration 'default' which is not declared in the module descriptor for my.group:artifact.name:16.06.29.5144
When I remove spring-boot plugin, then error disappears and I see expected output:
archives - Configuration for archive artifacts.
\--- my.group:artifact.name:16.06.29.5144
Any ideas why spring-boot plugin breaks dependency on custom configuration?
Your custom artifact looks to be another trigger of a bug/limitation in Gradle. The failure's occurring due to some logic in the dependency management plugin that Spring Boot's plugin uses that, among other things, ensures that any exclusions declared in dependencies' poms are applied as intended.
You can work around the problem, at the cost of perhaps having to declare some additional exclusions, by telling the dependency management plugin not to apply Maven exclusion semantics:
dependencyManagement {
applyMavenExclusions false
}
I keep getting this error. Any ideas?
What went wrong:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:classpath'.
Could not find com.android.tools.build:gradle:2.0.0-beta7.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-beta7/gradle-2.0.0-beta7.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-beta7/gradle-2.0.0-beta7.jar
You are referring maven central for finding android plugin artifacts, android gradle plugin is published at jcenter
add jcenter() to buildscript.repositories block in your root build.gradle file.
It should look like as below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:X.X.X' // your verison
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}