Gradle artifactory plugin cannot resolve dependency on configuration phase - gradle

I am trying to resolve dependency in configuration phase with artifactory gradle plugin.
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
artifactory {
contextUrl = "${artifactory_contextUrl}"
...
resolve {
repository {
repoKey = 'repo'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
dependencies {
compile 'commons-lang:commons-lang:+'
}
task testCustomResolve {
logger.quiet configurations.getByName('compile').singleFile.absolutePath
}
And it gives me
Could not resolve all dependencies for configuration ':compile'.
Cannot resolve external dependency commons-lang:commons-lang:+ because no repositories are defined.
It works as a charm in execution phase
task testCustomResolve << {
logger.quiet configurations.getByName('compile').singleFile.absolutePath
}
or when I use mavenCentral()
repositories {
mavenCentral()
}

In case you don't need to publish to Artifactory, I noticed that it works better if you don't use the artifactory {} syntax. Instead, try using:
plugins {
id "com.jfrog.artifactory" version "4.4.10"
}
repositories {
mavenLocal()
maven {
url "${artifactory_contextUrl}/${artifactory_repo}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
mavenCentral()
}

Related

publish final jar file in artifactory using gradle

I am trying to publish jar file (output of a gradle project) to jfrog/artifactory. The project is successful when I execute gradlew build or gradlew build artifactoryPublish. I also see on console that Build successfully deployed. Browse it in Artifactory under https://... but when I go to Artifactory the nothing is there. I tried following the jfrog/artifactory documentation, some questions on stackoverflow like this one and this one. Following is the snippet from my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
allprojects {
apply plugin: "com.jfrog.artifactory"
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
task sourceJar(type: Jar){
from file("build/libs/mygradle-1.0.0-sources.jar")
classifier = 'sources'
}
task certify(type: Zip, group: 'build', dependsOn: 'build') {
from ("build.gradle")
from ("libs")
from ("src/test")
from ("build/libs")
from ("${buildDir}/reports/tests")
archiveFileName = "certify-resources.zip"
destinationDirectory = file("${buildDir}/certify")
}
version = '1.0.0'
group = 'com.mypro.test' // this is the package prefix the jar will go into artifactory
artifacts {
archives sourceJar
}
publishing {
publications {
pluginJar(MavenPublication) {
groupId "${group}"
artifactId 'mygradle' // this is the package suffix the jar will go into in artifactory
version "${version}"
artifact sourceJar
from components.java
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'gradle-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
I am not sure what I am missing. Could anyone suggest what I missed. Thanks
EDIT: I created new instance of rhel/artifactory and a new gradle project just to be sure that the issue is not coming from somewhere else but still
only this information Build-info successfully deployed. Browse it in Artifactory under http://100.100.11.11:8081/artifactory/webapp/builds/mygradle/1675035714284 is showing when I execute gradlew build artifactoryPublish with
BUILD SUCCESSFUL
The JAR component can be extracted from components.java.
Try to add it to the publication as following:
pluginJar(MavenPublication) {
groupId "${group}"
artifactId 'my-published-project'
version "${version}"
artifact sourceJar
from components.java // <- add this line
}
the java component in its default setup consists of a JAR — produced by the jar task
For more information see Component terminology and Maven publications.
EDIT:
Also, since "pluginJar" is not a default publication name, we should add the publication to the list (the plugin adds mavenJava and ivyJava by default).
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'gradle-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications('pluginJar') // <- add this
}
}
...
}

Not able to download jar from Artifactory repository in gradle project

I want to connect to the Artifactory repository
https://www.artifactrepository.citigroup.net/artifactory/webapp/#/artifacts/browse/tree/General/
and download a jar using build.gradle.
I have 2 repository in my code, which I want to connect: one is local and is where I've download all Gradle related jars and the other is artifactory repository where I want to download TIBCO related jars.
but not able to connect to second repo
This is my build.gradle code
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
}
maven {
url 'https://www.artifactrepository.citigroup.net/artifactory/maven-cto-dev-3rdpartymanual-local'
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
allprojects {
apply plugin: 'artifactory'
apply plugin: 'maven'
group = 'com.citi.recon'
task wrapper(type: Wrapper) {
distributionUrl = "${artifactory_contextUrl}/simple/ext-release-local/org/gradle/services/distributions/gradle/1.9/gradle-1.9-bin.zip"
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '1.9'
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
maven = true
}
}
resolve {
repository {
repoKey = 'repo'
maven = true
}
}
}

download jars and wars from artifactory and copy to a specific folder using gradle

I am new to gradle and artifactory and trying to download jars and wars from artifactory and copy to a specific folder using gradle. How can I do this?
My artifactory repository is a generic one where in I am uploading all the jars and wars. From here I want to download them and copy them to a folder.
This is what I got from the artifactory. I replaced the repoKey with my-repo where the jar and war files are located.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'my-repo-upload'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'my-repot'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}

Gradle is not able to use dependencies from artifactory

This is the code I have written: Please be notified that the code is working when I enable the flatDir section (commented one in the code), but not working when I want to use Remote Artifactory repository (Means comment the flatDir part):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'distribution'
buildDir = new File("$buildPath", project.name)
ext.distributionDir = new File(project.buildDir, 'distribution')
sourceSets {
//SourceSets
}
ext.sharedManifest = manifest {
//Manifests
}
tasks.withType(Jar) {
//Code to generate Jar Artifacts
}
// repositories {
// flatDir {
// dirs file("$dependencyPath"),
// }
// }
allprojects {
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
}
}
project(':projectName:ProjectComponent') {
sourceSets {
main {
java { include '/pathToCode/*' }
}
}
dependencies { compile (group: 'jcifs', name: 'jcifs', version: '1.1.11')}
//******* Publishing Component Jar (Build artifacts on Remote Repository) ********//
publishing.publications {
mavenJava(MavenPublication) {
groupId 'GroupID'
artifactId project.name
version = projVersion
from components.java
}
}
artifactoryPublish {
publications(publishing.publications.mavenJava)
}
}
Please suggest the solution.
Thanks! :-)

Multiple maven repositories in one gradle file

So my problem is how to add multiple maven repositories to one gradle file.
This DOESN’T work:
repositories {
mavenCentral()
maven {
url "http://maven.springframework.org/release"
url "http://maven.restlet.org"
}
}
you have to do like this in your project level gradle file
allprojects {
repositories {
jcenter()
maven { url "http://dl.appnext.com/" }
maven { url "https://maven.google.com" }
}
}

Resources