Java Spring Boot project error on download gradle dependency - spring

One of my coworkers recently deleted his ".gradle" directory. He was not able to build the project again, because of the following error:
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://repo.spring.io/plugins-release/com/github/node-gradle/gradle-node-plugin/2.2.1/gradle-node-plugin-2.2.1.pom'.
at org.gradle.internal.resource.ResourceExceptions.failure(ResourceExceptions.java:74)
at org.gradle.internal.resource.ResourceExceptions.getFailed(ResourceExceptions.java:57)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.downloadByCoords(DefaultExternalResourceArtifactResolver.java:138)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.downloadStaticResource(DefaultExternalResourceArtifactResolver.java:97)
at org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver.resolveArtifact(DefaultExternalResourceArtifactResolver.java:64)
at org.gradle.api.internal.artifacts.repositories.metadata.AbstractRepositoryMetadataSource.parseMetaDataFromArtifact(AbstractRepositoryMetadataSource.java:69)
at org.gradle.api.internal.artifacts.repositories.metadata.AbstractRepositoryMetadataSource.create(AbstractRepositoryMetadataSource.java:59)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.resolveStaticDependency(ExternalResourceResolver.java:244)
at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.doResolveComponentMetaData(MavenResolver.java:127)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveComponentMetaData(ExternalResourceResolver.java:445)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.resolveComponentMetaData(CachingModuleComponentRepository.java:378)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.resolveComponentMetaData(ErrorHandlingModuleComponentRepository.java:138)
And I tried to access the URL 'https://repo.spring.io/plugins-release/com/github/node-gradle/gradle-node-plugin/2.2.1/gradle-node-plugin-2.2.1.pom' directly on browser, and it's now asking user and password.
Did somewone known what's happening? Did this repo was moved to another host?
Thanks in advance.
edit: My gradle repositories:
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2/" }
}

Looks like you are downloading from a jfrog repository and are missing the gradle.properties file ..
The .gradle folder contains a file called "gradle.properties" which contains the credentials (usually encrypted from the above repo in case of employer controlled repo)to access the jars/poms.
The steps to generate and download :
1.Go to https://repo.spring.io/ and login if you have workplace credentials for accessing the repo.
2.search for "plugins-release" is the "set-me-up" scroller.
3. select Gradle in "tools" drop-down and Generate gradle.properties.
4.download this "gradle.properties" and put it in .gradle folder under the username directory.

switch the order of the last 2 lines under repositories. It becomes:
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.spring.io/plugins-release" }
}
This way Gradle will resolve gradle-node-plugin from the official Gradle plugin portal (https://plugins.gradle.org/m2/), instead of from Spring's Artifactory (which caches 3rd party artifacts, but you don't really want to fetch non Spring plugins from it).
Also see this answer: https://stackoverflow.com/a/22170251/2591231
PS:
I am assuming that in your build.gradle you apply the plugin "com.moowork.node" as shown here under "Using legacy plugin application", and that the repositories block is inside a buildscript block. Otherwise, your repositories block has no effect on plugin resolution.

Related

What is maven { url "https://jitpack.io" } in build.gradle file meaning?

What is maven { url "https://jitpack.io" } in build.gradle file meaning?
Do I have control over project or I depend on jitpack.io developer account/libraries?
jitpack.io compile source code from github
By adding this repository to your project, you can use public's github repository in your project.
I don't know if it is possible to use a private repository requiring an account.

Artifactory directory contains dots, can't resolve dependencies with Gradle 6.5

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).

Maven local repository pointing wrong location

In my Android project I've defined mavenLocal() as repository in the root build.gradle file. However, if I publish changes to mavenLocal these will not be recognized by my project. However, if I define the location explicitly the changes ARE found, proving that the changes are correctly published. So it seems like my mavelLocal is not pointing to the default location?
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
allprojects {
repositories {
mavenLocal() // picks wrong location?
// maven { "C:/Users/<username>/.m2/repository/" } // mavenLocal fallback
maven { url nexusRepositoryUrl }
maven { url nexusSnapshotsUrl }
maven { url nexusReleasesUrl }
mavenCentral()
google()
maven { url "https://maven.google.com" }
jcenter()
}
}
How can I solve this? I'm working with several people in one project, so the fallback method isn't a solution. Of course I could use a variable user path, but that's not what I'm looking for:
maven { url System.getenv('USER_PATH') + "/.m2/repository/" }
I do not have a settings.xml file in /.m2 directory (which can be used to override the default maven local repository location). I could create one to solve the problem, but it feels unnecessary to change the 'default' location to the 'default' location.
So I'm specifically looking for the reason why the default implementation of mavenLocal() doesn't seem to work.
EDIT
This following might be either related or an unrelated problem / question: I've got some trouble with old caches of repositories not being replaced by new ones, so that might also be an issue in this case. I don't have much knowledge about how gradle caching works, so if someone could provide me a clear solution for this, then it might also solve the problem. I'm able to clear cache sometimes, but the problem keeps returning, and I need a permanent fix for it.
Caches seem to be temporarily updated after a combination of any of the following (not order specific, and haven't been able to find out which are exactly required to fix my problem):
Android Studio > File > Invalidate caches & restart
Remove mavenLocal definition in build.gradle > sync project > add mavenLocal definition > sync project
Run > Clean Project > Rebuild project
Install & run project on device

How to add an additional repository at the top of the list for a particular subproject in Gradle

I have a multi project setup in Gradle, the root of which specifies a bunch of repositories that are shared by all subprojects:
subprojects {
repositories {
maven { url '...' }
mavenLocal()
mavenCentral()
}
}
How can I specify an additional repository for a particular subproject, and have it as the first in the list of repositories?
Why do I need to do this? I need to include an Android library in .aar format. It is present in .aar format in this additional repository, and in .apklib format in Maven Central. If Gradle hits Maven Central first and finds the .apklib it will bail out.
By postponing the addition of the repositories in the root build script, the repositories are added after the ones added in the subproject:
subprojects {
afterEvaluate {
repositories {
maven { url '...' }
mavenLocal()
mavenCentral()
}
}
}
i would recommend to use something for external&internal repository management.
i think that artifactory or nexus can handle remote/virtual repositories, and makes it possible to use only one repository in your project.
note: if repository order is relevant to you, that might mean that the artifact identifier (group:ident:version) can mean different artifacts - i think that violates some maven/etc guideline which can cause invalid caches behind gradle and cause mysterious problems

How to set global repositories for gradle that I can use them in each gradle project

It's slow to visit the maven official repositories from my country, so I want to try some local repositories first.
Is it able to add them to some global gradle configuration file, that I can just use them in each gradle project, without modifying the project-scope build.gradle file?
I would suggest to use the init.gradle script which is located in your home folder $HOME/.gradle/init.gradle which might contain the following content:
allprojects {
repositories {
mavenLocal()
maven {
url "http://localhost:8081/nexus/content/groups/public/"
}
}
}
I guess that what are You looking for are init scripts.

Resources