I'm developing a very basic Gradle plugin (mainly to get experience) and I've published a version to my Bintray repository which should be viewable here.
I've linked my repository to JCenter (and can find my plugin here) and now, to test it all works, I'm trying to download those artifacts from a Gradle build script and apply my plugin to a mock project:
apply plugin: 'semver'
apply plugin: 'java'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.tagc:semver-plugin:0.1.0'
}
}
semver {
versionFilePath = 'version.properties'
}
However, Gradle can't resolve that dependency and throws this exception:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'TestSemver'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find com.github.tagc:semver-plugin:0.1.0.
Searched in the following locations:
https://jcenter.bintray.com/com/github/tagc/semver-plugin/0.1.0/semver-plugin-0.1.0.pom
https://jcenter.bintray.com/com/github/tagc/semver-plugin/0.1.0/semver-plugin-0.1.0.jar
Required by:
:TestSemver:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.703 secs
This is because JCenter doesn't seem to be hosting my files (under com/github/tagc). I'm not sure why this is the case. After getting a confirmation that my repository is linked with JCenter, are there any additional steps I need to take to make it host my uploaded files so that I can access them in the way shown in the build script? Or is just that it takes some time for the files to appear on JCenter? It's been about 5 hours since my repository was linked to JCenter.
Any help or advice would be appreciated.
It turns out that I just needed to be patient and let JCenter update. It's on there now, and my build script runs fine.
Considering that it takes a fair amount of time to update (~12 hours for me), I think that the user experience might be improved by letting first-time users know that there's a lengthy update process and that they haven't simply missed a step. This would remove some of the anxiety of wondering "Have I missed a step, and if so will I be waiting forever?"
Other than that, the Bintray UX is absolutely wonderful.
Related
I have a Maven package I've hosted on GitHub package registry.
Whenever I make an update to the package I run mvn deploy to publish the changes, but if I simply run gradle install on the dependent application it doesn't seem to install the latest version of the package
(not sure if settings.xml is relevant to this question so I removed it, but it can be seen at the link to my previous question).
I had a similar issue with using the latest snapshot version of the package in another dependent, which was using Maven as the package manager/build tool instead of Gradle. That was resolved by checking a box to "always update snapshots" in Maven settings. I have checked the box in this project as well, but it doesn't seem to resolve the issue now.
What I have tried:
Invalidating cache and restarting IntelliJ
reimporting all gradle projects
deleting the dependency from my build.gradle and then reimporting projects and install, followed by adding it back and reimporting all projects and install
running ./gradlew build -x test --refresh-dependencies (test disabled because they were failing)
This is the log after I run gradle install:
4:07:08 PM: Executing task 'install'...
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar SKIPPED
> Task :install
BUILD SUCCESSFUL in 2s
3 actionable tasks: 1 executed, 2 up-to-date
4:07:10 PM: Task execution finished 'install'.
In my build.gradle I use the following syntax for my dependency (under dependencies):
compile('com.companyname:packagename:0.0.3-SNAPSHOT')
and this is what I have under repositories:
maven {
url "https://maven.pkg.github.com/companyname/packagename"
credentials {
username "TaylorBurke"
password "*****************"
}
}
Not sure if it is related, but when I go into my Maven settings to try and update the repository I get this error:
So there it is, I think I've included everything. Is it a configuration issue with Maven, Gradle, or IntelliJ?
Edit: because it has been suggested to close this question I am pointing out that the link to the other question does not address installing with Gradle, it simply addresses an error after running mvn deploy. I have already deployed the new package successfully and can get the new version from my other application. My problem is specific to gradle install. Even though the accepted answer mentions he had a similar problem using Gradle (but my problem is not with deploying either) he goes on to say that snapshot versions would provide a solution to the problem expressed, and I am already using a snapshot version in this package. That question is clearly quite different and not at all related to mine.
You have tried quite a few things with IntelliJ, but the problem happens when you run the build from the command line (./gradlew build). That should be a good indication that the problem is not with IntelliJ.
By default, Gradle will cache changing dependencies (e.g. SNAPHOST dependencies) for 24 hours. During that time, it will not ask the repository for newer versions. So if you publish a new version under the same name, Gradle might not see it for another day.
Using the --refresh-dependencies option will make Gradle ignore the cache, and thereby download the artifacts again.
You can also change the cache retention period through a ResolutionStrategy. You can also configure it to always check for changed dependencies if you like.
Read more about dynamic dependencies here: https://docs.gradle.org/current/userguide/dynamic_versions.html
If you are curious, the Gradle artifact cache is by default located in $USER_HOME/.gradle/caches/modules-2/files-2.1 (the numbers may be different depending on which version of Gradle you are using). This cache is unrelated to the one you mention in IntelliJ.
Also, the authentication error in the IntelliJ maven repository browser is because your credentials are in the Gradle configuration and not in IntelliJ. So this is also unrelated to Gradle.
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:+'
I have a hosted Sonatype Nexus repository on a local network. It has a Maven group containing a proxy repository for the public Maven repository. In the past this configuration was superb and I encountered few issues.
I recently configured https and ssl on the Nexus repository as Docker would not easily log into insecure Nexus Docker registries during CI/CD processes. I did end up re-configuring the Maven repositories at this point.
Then I updated build.gradle:
repositories {
maven {
credentials {
username "${nexusUsername}"
password "${nexusPassword}"
}
name = 'RepositoryName'
url = "https://${nexusURL}:${nexusPort}/repository/maven-public"
}
}
with the nexus* variables defined in ~/.gradle/gradle.properties:
nexus<Variable>=<value>
I have also added the appropriate certificate to the java jre keystore with the keytool and added the certificate in Idea's settings (File > Settings... : Tools > Server Certificates).
When trying to download dependencies (through the Maven proxy) using Gradle (by clicking "import changes" on the pop-up notification in Intellij Idea) the Build output shows "Could not resolve: <dependency>" for each dependency. This behavior is consistent across all of my projects (even ones that previously were able to resolve dependencies).
I have, under most circumstances, been able to get the dependencies to resolve through Nexus when running a Gradle task (:dependencies, :idea, :build) from the project's build.gradle file from a command line. The resulting downloads are not available to the project in Idea. However, after the dependencies have been resolved once, the artifacts are cached in Nexus's Maven proxy repository allowing Gradle/Idea to correctly resolve all dependencies.
What could be causing Gradle/Idea's failure to resolve artifacts through Nexus's Maven proxy? Is there a way to get Gradle/Idea to correctly resolve dependencies through the Nexus Maven group/proxy?
For now I've just added mavenCentral() to the repository list in build.gradle but I would prefer to only include the Nexus Maven group in the future. Caching resources for 1GB/s download is really nice. I would also like to better understand Gradle/Idea and what is causing this issue.
More information:
Intellij Idea has been reinstalled to version 2018.2.6 Build #IC-182.5107.16 during the process of trying to fix this issue. The old version is lost to history.
Gradle has been updated to version 4.10.2. Previous version was 4.5.1.
I've printed each of the nexus* variables via println to ensure the values were correct.
No configuration of Idea's settings for Gradle (local Gradle distribution, default Gradle wrapper, Gradle 'wrapper' task configuration) managed to resolve dependencies.
Every configuration of deleting at least one of ./.idea, ./.gradle, and ~/.gradle/caches was tried.
Idea is not in offline-mode. Sequences of toggling offline-mode and "Refresh all Gradle projects" did not change the outcome.
I have run an Idea configuration of Gradle's dependencies task with --warning-mode all --debug and compared the log to the output of gradle dependencies --warning-mode all --debug on command line. The logs seem to be producing the same statements (in wildly different orders) until the "Could not resolve:" message appears in the Idea output. I did not find any nearby error messages that would explain the failure. If it would help diagnose the issue I can upload those files.
I have tried setting the repository to point directly at the Nexus Maven proxy instead of the Maven group. This did not allow Gradle/Idea to resolve dependencies.
Should I be using a http/https proxy for Gradle? I don't understand the goal of using a proxy in this context.
I have not done anything with Grail. I don't know what Grail is and suspect I do not currently need it.
OS is Windows 10.
Dependencies are not resolved when using compile or implementation in build.gradle.
Transitive dependencies don't seem to be relevant.
I must not have added the certificate to the correct jre installation. I added it more recently and the issue was resolved.
Also, superstitious notes for anyone else having a similar issue:
I added the certificate (a wildcard certificate) under the alias (using the -alias command line parameter for keytool): *.example.com
I also added it under an alias for the full address: nexus.example.com
I don't know whether either of those had any impact on Idea/Gradles' success in resolving artifacts. I believe it was working before I added the second alias.
I am using Artifactory as my artifact store, and have set this up so that it is being used as a proxy and cache for jcenter. This generally is working fine apart from for dependencies declared in the buildscript block in my main build.gradle.
My block looks like
buildscript {
repositories {
//proxies jcenter
maven {
url "https://<myArtiInstance>/artifactory/repo"
credentials {
username artifactory_reader_username
password artifactory_reader_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
classpath "com.android.tools.build:gradle:2.1.2"
}
}
which gives the error when running gradlew clean build (2.10)
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find builder.jar (com.android.tools.build:builder:2.1.2).
Searched in the following locations:
https://<myArtiInstance>/artifactory/repo/com/android/tools/build/builder/2.1.2/builder-2.1.2.jar
If I wack the above url into my (authenticated) browser, I get the jar and can see its put into the arti cache.
All my other proxied dependencies seem to work so I am a bit confused as to whats going on.
At present I am wondering if this is a bug with Gradle 2.10 or something, as this used to work as I can see previous cached versions of that artifact in my arti box.
Thanks for any help or pointers :)
EDIT: If I roll back to com.android.tools.build:gradle:2.1.0 which is not in my cached repo either, build completes fine and it caches it. For some reason it does not like 2.1.2, I wonder why?!
EDIT2: Still having issues, now its taken issue with https://<myArtiInstance>/artifactory/repo/com/google/guava/guava/15.0/guava-15.0.jar which gives a similar error to the above
* What went wrong:
A problem occurred configuring root project '<name>'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find guava.jar (com.google.guava:guava:15.0).
Searched in the following locations:
https://<myAriInstance>/artifactory/repo/com/google/guava/guava/15.0/guava-15.0.jar
This is again from a dependecency specified inside the buildscript block. Any ideas whats going on? This time is transative so I cant just swap the version. The only strange thing I notice from the error messages is that its looking for guava.jar at the url ending in guava-15.0.jar...
So it turns out inspecting the output of gradlew clean build --debug for a second time, I noticed everything was being obtained from the local ~/.gradle/cache, apart from the failing jars above. rm the cache and everything works fine, and the transitive dependencies can be obtained from the url given in the error msg. Subsequent builds which retreive from local cache work fine. Seems to me that something had corrupted the local cache (maybe partial download of complete resources i.e. pom, jar etc for the dependency) and that the gradle error msg was incorrect.
EDIT: testing just deleting the jar from cache and still compiles fine...
I am learning basic Spring by following this tutorial.
I run this command to clone the demo basic project:
git clone https://github.com/spring-guides/gs-rest-service.git
Then I use intelliJ to import the cloned Gradle project.
However, it always downloading things from Internet, and sometime pop up alert says xxx is not found.
My question is what is it doing exactly? who and where I tell the code to download things?
It is really confusing to me because I couldn't figure out what is going on.
The project uses gradle to build the application, and the build.gradle file is telling gradle that this project needs some dependent libraries to run.
If you look in the build.gradle file, you will find these lines, which are pulling libraries from a central artifact repository (Maven Central in this case).
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
These libraries are dependencies and are necessary for this project to function, and so they must be downloaded. With that said, it should only need to download them once, after which they should be kept in the gradle artifact cache.