Download latest release from Artifactory with Gradle - gradle

Artifactory has a feature of their API where you can download the latest release of a jar file (See http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-RetrieveLatestArtifact).
Their example is:
GET http://localhost:8080/artifactory/ivy-local/org/acme/[RELEASE]/acme-[RELEASE].jar
I'm working on a project where all builds get published and I want to grab the jar from the last one. So what I'm looking for is a dependency like this in gradle:
compile "org.acme:acme:1.0.0.9.[RELEASE]"
This fails due to escaping of the square brackets so I tried:
compile "org.acme:acme:1.0.0.9.%5BRELEASE%5D"
This seems to allow gradle/ivy to find the file but it fails because the .pom file version does not match what is defined.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':project:compile'.
> Could not resolve org.acme:acme:1.0.0.9.%5BRELEASE%5D.
Required by:
org.acme:acme:unspecified
> Could not resolve org.acme:acme:1.0.0.9.%5BRELEASE%5D.
> inconsistent module metadata found. Descriptor: CachedResource: /Users/xxxx/.gradle/caches/artifacts-26/filestore/org.acme/acme/1.0.0.9.%5BRELEASE%5D/pom/3986d9c1a27873ce92c0dbd089fc1ca9618f8c1a/acme-1.0.0.9.%5BRELEASE%5D.pom for http://localhost/artifactory/org/acme/acme/1.0.0.9.%5BRELEASE%5D/acme-1.0.0.9.%5BRELEASE%5D.pom Errors: bad version: expected='1.0.0.9.%5BRELEASE%5D' found='1.0.0.9.80'
Is there any way to get gradle and ivy to pull the latest release from artifactory?

I was able to get this working using the ivy syntax:
compile "org.acme:acme:1.0.0.9.+"
This solves the problem I have but I never did manage to get it working using the Artifactory [RELEASE] url.

Related

Issue while trying to setup the spring-boot open source project from Github

I was trying to setup the spring boot open source project in order to contribute it. I was going through the steps in here. I am on the main branch. When I try to run
./gradlew build
I am getting this error
* Where:
Settings file '<my local path>/spring-boot/settings.gradle' line: 26
* What went wrong:
Plugin [id: 'io.spring.ge.conventions', version: '0.0.12'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'io.spring.ge.conventions:io.spring.ge.conventions.gradle.plugin:0.0.12')
Searched in the following repositories:
MavenRepo
Gradle Central Plugin Repository
maven(https://repo.spring.io/release)
maven2(https://repo.spring.io/snapshot)
settings.gradle contains this at line 26
id "io.spring.ge.conventions" version "0.0.12"
From what I understand in the above log, gradle is trying to search for io.spring.ge.conventions but its not able to find it in those repositories. I haven't used gradle before so I am not sure what the issue is exactly and how to fix it.
These are my system details:
System: Mac(Intel)
java version "17.0.5" 2022-10-18 LTS
Editor: Intellij
I don't have gradle installed separately. I am using the gradle wrapper provided by the project.
Additionally I just commented out that line in settings.gradle and ran the build. It succeeded.
Can anyone help me out on this?

Could not able resolve javax.inject: javax.inject:1.0 - Gradle

I am getting below error while running Gradle build in Unix terminal.
Could not resolve all files for configuration ':imcalmsvc-service:compileClasspath'.
Could not find javax.inject:javax.inject:1.0.
Searched in the following locations:
- https://jcenter.bintray.com/javax/inject/javax.inject/1.0/javax.inject-1.0.pom
- https://repo.maven.apache.org/maven2/javax/inject/javax.inject/1.0/javax.inject-1.0.pom
However, there is no error while doing Eclipse-> Gradle refresh.
The error means the dependency wasn't found in either JCenter or Maven Central. When you are usure about the exact name of dependency or which repositories it is uploaded to, I recommend a search engine like mvnrepository.com. It aggregates metadata from a lot of different Maven repositories and even shows you how to use them in Gradle.
In your case, you can find the javax.inject library here. Notice that the only published version is simply 1 and not 1.0. Change this and it should work.

Unable to load Maven meta-data from private repo. Received 403: Forbidden

I'm trying append a private dependency into my project (react-native-android) via Maven. Unfortunately I'm get following error message when I try to build ./gradlew assembleDebug my project.
Error message returned as below:
> FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not resolve com.facebook.react:react-native:0.19.+.
Required by:
project :app > project :react-native-i18n
> Failed to list versions for com.facebook.react:react-native.
> Unable to load Maven meta-data from https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml.
> Could not get resource 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'.
> Could not GET 'https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml'. Received status code 403 from server: Forbidden
Code example
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url "https://xxxPRIVATE_REPOxxx/android" }
}
dependencies {
implementation project(':react-native-i18n')
implementation 'com.android.support:support-v4:+'
implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+'
}
I have read numerous post and research on maven and gradle's topic. Here's my finding towards my issues:
Meaning that my sequence of declaring maven by right will get the "correct/suitable" module from the first declared maven instead of the following (maven xxxPRIVATE_REPOxxx)
The order of declaration determines how Gradle will check for dependencies at runtime. If Gradle finds a module descriptor in a particular repository, it will attempt to download all of the artifacts for that module from the same repository. You can learn more about the inner workings of dependency downloads.
Returning of 403 Forbidden does not necessary mean I do not have access to the repo I'm trying to access, but also missing of resource.
Hence I made an assumption here... During the download of project dependencies, Maven loop through both maven repo (maven google & xxxPRIVATE_REPOxxx) to get the suitable lib. However when it reaches xxxPRIVATE_REPOxxx, it failed to locate maven-metadata.xml therefore result with https://xxxPRIVATE_REPOxxx/android/com/facebook/react/react-native/maven-metadata.xml and 403 Forbidden.
My question:
Should there be a way to indicate which dependency to get from which Maven?
I was imaging something like this
implementation 'xxxPRIVATE_DEPENDENCYxxx:1.0.+' : xxxPRIVATE_REPOxxx (You know what I mean)
I have tried:
Upgrading my Android-Plugin to 3.5.0
Upgrading my Gradle version to 5.6.4
./gradlew clean and re-build after steps 1 and 2
Turns out the issue was because the react native dependencies use by 3rd party library (react-native-i18n) was too low. You can find it at react-native-i18n's build.gradle.
dependencies {
compile 'com.facebook.react:react-native:0.12.+'
}
Hence my fix to this was update the code to
compile 'com.facebook.react:react-native:+'

Gradle Plugin Test Project Build Failing

I downloaded the gradle plugin test project from their github here:
https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/customPlugin
I also updated gradle to latest (4.7).
When I gradle build the consumer project, I get the following build error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'consumer'.
Could not resolve all artifacts for configuration ':classpath'.
Could not find org.gradle:customPlugin:1.0-SNAPSHOT.
Searched in the following locations:
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/maven-
metadata.xml
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/custom
Plugin-1.0-SNAPSHOT.pom
file:/C:/Code/gradle/subprojects/docs/src/samples/customPlugin/repo/org/gradle/customPlugin/1.0-SNAPSHOT/custom
Plugin-1.0-SNAPSHOT.jar
Required by:
project :
What's the issue here? I guess I don't understand gradle plugins enough. Does the plugin need to be built somehow? I have no 1.0-SNAPSHOT pat or anything of the sort, which seems to be where its looking.
Does the plugin need to be built somehow ?
Yes, at first, otherwise the consumer project won't find it.
Inside the plugin project, just run gradle uploadArchive
And then retry a gradle build inside the consumer project

Error: DefaultOperationDescriptor#2b878eea already available in Android Studio

Failed to complete Gradle Execution
When I try to Sync Gradle with Project Files, the error mentioned below appears
Android Studio version that I am using is 3.0.1, Gradle Build 4.1-all.zip
FYI, I have already tried ->Build->Clean Project and Invalidate Cache & Restart and one more thing is that there is no error in my code.
Message Error:
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
Error:Failed to complete Gradle execution.
Cause:
Operation org.gradle.tooling.internal.provider.events.DefaultOperationDescriptor#86028ba already available.
BUILD SUCCESSFUL in 8s
Information:1 error
Information:0 warnings
But When I try to Run on my Emulator
The error below appears
Message Error At Run Time
Information:Gradle tasks [:app:assembleDebug]
E:\Android Game App\app\build.gradle
Error:(1, 1) A problem occurred evaluating project ':Android Game App:app'.
Failed to apply plugin [id 'com.android.application']
Due to a limitation of Gradle new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error.
This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently.
To resolve this issue, add the Android Gradle plugin to only the buildscript classpath of the top-level build.gradle file.
In the case of composite builds, also make sure the build script classpaths that contain the Android Gradle plugin are identical across the main and included projects.
If you are using a version of Gradle that has fixed the issue, you can disable this check by setting android.enableBuildScriptClasspathCheck=false in the gradle.properties file.
To learn more about this issue, go to https://d.android.com/r/tools/buildscript-classpath-check.html.
Information:BUILD FAILED in 16s
Information:1 error
Information:0 warnings
Information:See complete output in console
Nothing found on Google! Any help would be highly encouraged???
The key to the problem is this line. Maybe due to a project.all in root build.gradle or you are using composite builds.
This can occur when the build script classpaths that contain the Android Gradle plugin in sub-projects,
or included projects in the case of composite builds, are set differently.
that mean in all yours build.gradle you have more than one this line
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:x.y.z"
}
}
what this means is that with the introduction of Android Gradle Plugin 3.Y.Z and the new way of handling dependencies,
if you mix in the same project 2 projects with different plugin version (one with a 2.3 and other with 3.0.1) you will get dragons while compiling.
And this error it's a way to force developer to check it and opt-out once detected and solved.
how to solve it, first ensure you don't use a android gradle plugin below 3.0.1 and use the new dependencies configurations, and add this property on every gradle.properties you have.
android.enableBuildScriptClasspathCheck=false
with that you can now compile
one example could be found at realm sample repo they use a allprojects block that include android gradle plugin on every module. and solve it adding previus gradle property at root gradle.properties

Resources