How to check where gradle is downloading its dependencies from? - maven

I have a project using gradle from building and due to some recent jcenter issues, we want to move all our dependencies to our artifactory. Now i have all the configuration ready and declared inside the gradle build files. I have also removed all traces of other maven repositories.
repositories {
maven {
url "${artifactory_contextUrl}/repo_name-generic"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
After doing a gradle clean build, i expected a lot of errors as i have never added those dependencies to our artifactory repo, but none came. The project builds fine and i can see them being downloaded.
My question now is, why is it working?
Is there a way i can check from which source the dependencies are coming from?
Also in artifactories GUI i cannot locate the packages inside the specified repo
Thanks!

If you ant to print the repositories a project is using, the following task will do it for you:
task printRepos {
doFirst {
project.repositories { repositories ->
repositories.forEach { repo ->
println("${repo.name}: ${repo.url}")
}
}
}
}
If you add it to your gradle build and invoke it gradle printRepos, you should get the repositories printed out
For more information regarding the API, check: https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/RepositoryHandler.html
https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
Also thanks to Bjorn for pointing out the doFirst/doLast problem.

rm -rf ~/.gradle/caches
./gradlew assembleDebug -i > ~/Desktop/dump
search dependency lib in dump file to check where it was downloaded from
For example, flexbox-2.0.1 was downloaded from jcenter:

Related

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

gradle can't download ua-parser file

I'm trying to test some jenkins job seed dsls and for that I needed to download in gradle all plugins jenkins had, one of them was blueocean and in my build.gradle I've got this line
testPlugins 'io.jenkins.blueocean:blueocean:1.23.2'
and I get thrown this exception
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find ua_parser:ua-parser:1.3.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- https://repo.maven.apache.org/maven2/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
- http://repo.jenkins-ci.org/releases/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- http://repo.jenkins-ci.org/releases/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
- https://jcenter.bintray.com/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.pom
- https://jcenter.bintray.com/ua_parser/ua-parser/1.3.0/ua-parser-1.3.0.jar
Required by:
project : > io.jenkins.blueocean:blueocean:1.23.2 > io.jenkins.blueocean:blueocean-rest-impl:1.23.2
I tried running with gradlew 4.8.1 and 6.0.1
I tried addint the ua-parser to build.gradle
compile group: 'ua_parser', name: 'ua-parser', version: '1.3.0'
I tried removing all gradle cache and refresh dependencies
rm -rf ~/.gradle/cache
./gradlew test --refresh-dependencies # or ./gradlew build ..
I disabled the vpn so it wasn't some firewall not allowing me to connect to the site, maybe I have some outdated gradle repository stored ? (I'm not familiar with gradle yet, so maybe something simple is escaping my sight)
EDIT 1:
I think this might be related to missing repository so tried adding new one by hand I found the https://github.com/jenkinsci/blueocean-plugin and tried add it to settings.gradle
sourceControl {
gitRepository("https://github.com/jenkinsci/blueocean-plugin.git") {
producesModule("org.gradle.blueocean:utilities")
}
}
and then referencing in build.gradle
dependencies {
...
implementation 'org.gradle.blueocean:utilities'
but doesn't seem to work, does anyone know how to add/where to search for gradle repositories (specifically with blueocean poms)
had to add those lines in repositories in build.gradle
repositories {
mavenCentral()
maven { url 'http://repo.jenkins-ci.org/releases/' }
maven { url 'https://mvnrepository.com/artifact/io.jenkins.blueocean' }
maven { url 'https://mvnrepository.com/artifact/ua_parser/ua-parser' }
maven { url 'https://mvnrepository.com/artifact' }
maven { url 'https://maven.twttr.com/' }

Gradle repository

Sorry, I'm either stupid, or Gradle repository management is really not there where it should be. I have an Eclipse (Mars) workspace with a mix of Maven and Gradle projects. Naturally, before committing anything on our VCS, I want to test locally. This means I mvn clean install an Artifact in order to have it in my local Maven repository. Obviously, part of the needed Artifact required by Gradle project are also on remote repository.
My Gradle repo are configured like this:
repositories {
mavenLocal()
maven { url "http://myrepo.mycompany.com/nexus/content/groups/public/" }
maven { url
"http://myrepo.mycompany.com/nexus/content/repositories/releases/" }
maven { url
"http://myrepo.mycompany.com/nexus/content/repositories/snapshots/" }
maven { url "http://myrepo.mycompany.com/nexus/content/groups/public-
snapshots/" }
}
Why Gradle goes fetch a resource until the last repo? I mean, I updated an Arifact, installed it locally ... obviously the Artifact which is on a remote repo is not yet the latest version ... why does Gradle go and fetch it?

Gradle: publish an artifact with a subset of files/dependencies of a project

I am lost in all these plugins :(
What I have so far, looks something like this:
artifactory {
contextUrl = artifactoryUrl
publish {
repository {
repoKey = project.repo
username = artifactoryUser
password = artifactoryPassword
maven = true
defaults {
publications('mavenJava')
}
}
}
version = "${majorVersion}${buildNumber}${snapshot}"
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier = 'sources'
}
}
}
}
I am sorry, I did write this myself, but, mostly by copying and pasting things from various examples I found on the web, so I am not sure what this is actually doing :(
Surprisingly, this works: I can do gradle artifactoryPublish, and uploads a pom file and two jars (classes and sources) to artifactory.
But, I need to modify it, so that I can publish a subset of the project as a different artifact, and only include the dependencies that it requires.
I managed to build a jar file:
task utilJar(type: Jar) {
from sourceSets.main.output.classesDir
include '**/util/*.class'
baseName 'basic-util'
}
I also defined a Configuration with a subset of dependencies:
configurations {
util
}
dependencies {
util "org.apache.commons:commons-lang3:3.4"
util "com.google.guava:guava:18.0"
}
artifacts {
util utilJar
}
This is where I get stuck. How do I get this new artifact published?
I tried following the same strategy:
publishing {
publications {
mavenUtil(MavenPublication) {
from components.java
artifact utilJar {
classifier = 'util'
}
}
}
}
artifactory {
defaults {
publications('mavenUtil')
}
}
(this is in a subproject, so I need it do be incremental)
This does not work:
Could not find method defaults() for arguments [build_8axxghkylu3559p5lal6spy1u$_run_closure7$_closure11#38abcbd4]
But, even if it did, it would still be not be quite what I need, because I don't know how I could then publish a particular artifact: the only way I could ever publish anything at all is gradle artifactoryPublish, but that does not ask me which artifacts to publish. Will it publish everything every time?
As you can see, I am hopelessly lost here :(
Could someone with a clue please show me the light?
UPDATE So, I removed the last artifactory closure from the build, and now I not getting the error, but still can't get it to do what I need.
My artifactory seems to be not in good mood right now, so I am publishing locally.
gradle publishToMavenLocal creates a single artifact as before, but adds my new "-util" jar to it. This is not at all what I want. I need a new, separate artifact, with that jar file, and its own set of dependencies.
Here: https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories I found a suggestion, that "The created task is named “publish«PUBNAME»PublicationTo«REPONAME»Repository”". This does not seem to to be true, because gradle publishUtilMavenPublicationToMavenLocalRepository (with all the case variations I could think off) says that there is no such task. :(
Have you tried using the set me up feature? It available for all version of Artifactory. It should provide a good starting point to configure you gradle project to work with Artifactory.
Specifically for Gradle it can assist you with generating the relevant configuration according to the repositories you wish to resolve / publish from / to, defining the relevant dependencies to install the jfrog plugin etc.

Gradle Plugin not found when using wrapper

I have a small gradle build which is using a 3rd party plugin it works great while running gradle commands I then added the wrapper task so I could distribute the code and it could be built with non gradle users. When I went to test the gradlew command I can not even run gradlew tasks it fails saying the plugin is missing.
Is there some other configuration that needs to happen?
My wrapper task:
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-2'
jarFile = 'wrapper/wrapper.jar'
}
Full build file: https://github.com/beckje01/Multi-Combobox/blob/master/build.gradle
Based on the documentation of this plugin you got to build it from the source code and put it into the directory lib/plugins of your Gradle distribution. My guess is that's what you did before you switched to the Gradle wrapper. Whenever you use the Gradle wrapper your locally installed distribution is not used anymore. Gradle downloads the distribution and puts it under ~/.gradle/wrapper/dists/gradle-1.0-milestone-2. One way to get this running would be to put the plugin in there as you did before. However, this won't make it running for somebody else that checks out your code and runs the build. This is the whole point of using the Gradle wrapper.
What I would do in your case is to upload the plugin artifact to a central repository and refer to it in your build script. It doesn't look like it would be available on Maven Central though. You can upload it to your GitHub project and refer to it in your build script like this:
buildscript {
repositories {
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = 'GitHub'
addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
}
mavenCentral()
}
dependencies {
classpath 'beckje01:jslib:0.5'
classpath 'com.google.javascript:closure-compiler:r706'
}
}

Resources