I would like to configure gradle with plugin for artifactory to push Android libraries. I don't have any issue with pushing aar files, but when pushing the POM I receive 409.
What went wrong: Execution failed for task ':artifactoryDeploy'.
java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors: The
target deployment path 'test/path.../0.0/name-0.0.pom' does not match
the POM's expected path prefix 'path.../0.0'
Current configuration:
artifactory {
contextUrl = "url"
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'test'
username = "test"
password = "test"
}
defaults {
publications('aar')
publishArtifacts = true
// Publish generated POM files to Artifactory (true by default)
}
}
}
I suppose there is an issue with adding repoKey before path. How can I force artifactory plugin to add repoKey ("test") before path?
Related
I have set the username and password for publishing to artifactory using gradle, however, the build fails on publishing the build.info.
artifactory {
publish {
contextUrl = 'http://localhost:8081/artifactory'
repository {
repoKey = "libs-snapshot-local"
username = "user"
password = "pass"
maven = true
}
defaults {
publications = ('mavenJava')
}
}
}
The user I am running gradle with doesn't have access to the artifactory repository but the user in the artifactory block does.
It seems like the build.info is being published to artifactory with the gradle user and not the user in the build.gradle.
How do I set the username/password so that the build.info is published using a user that has permissions?
There are two sets of Artifactory credentials you can configure for the Gradle Artifactory plugin:
Credentials used for artifacts resolution
repositories {
jcenter()
maven {
url "http://repo.myorg.com/artifactory/my-repo" // The Artifactory (preferably virtual) repository to resolve from
credentials { // Optional resolver credentials (leave out to use anonymous resolution)
username = "username" // Artifactory user name
password = "password" // Password or API Key
}
}
}
Credentials used for deploying artifacts and publishing build info.
This is the set of credentials you need to use for deploying the artifacts and build info into Artifactory.
You need to make sure this user has permissions for Repositories:Deploy and Builds:Deploy.
The OS user which is running gradle (gradle user) is not being used for authentication and is not recognized as an Artifactory user. It is, however, captured as part of the build info.
artifactory {
contextUrl = 'http://repo.myorg.com/artifactory' // The base Artifactory URL if not overridden by the publisher/resolver
publish {
contextUrl = 'http://repo.myorg.com/artifactory' //The base Artifactory URL for the publisher
//A closure defining publishing information
repository {
repoKey = 'my-repo' //The Artifactory repository key to publish to
username = 'stackoverflow' //The publisher user name
password = 'password' //The publisher password or API key
}
}
}
The expected behavior is that when running the following command
./gradlew clean artifactoryPublish
The build artifacts and build info will be deployed to Artifactory
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.jar
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.pom
> Task :artifactoryDeploy
Deploying build descriptor to: http://127.0.0.1:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://127.0.0.1:8081/artifactory/webapp/builds/gradle-example-minimal/1602276439713
BUILD SUCCESSFUL in 903ms
7 actionable tasks: 7 executed
In Artifactory you will see that the artifacts where deployed using the username specified in the publish section
As well as the build-info JSON file
In the build info you will see that 2 user types are being captured:
Artifactory principal - this is the Artifactory user which was used to deploy the build info
Principal - this is the OS user which was running the gradle build. This information is captured inside the build info JSON as "principal"
I am trying to publish an RPM artifact from our project into a Yum Repo on Nexus via Gradle:
publishing {
repositories {
ivy {
url 'http://myrepo:8081/repository/myproject'
credentials {
username "aaa"
password "xxx"
}
layout "pattern", {
artifact "${buildRpm.outputs.getFiles().getSingleFile().getName()}"
}
}
publications {
rpm(IvyPublication) {
artifact buildRpm.outputs.getFiles().getSingleFile()
}
}
}
}
When I run ./gradlew publish this task gets picked up and starts to upload the main .rpm artifact of 90MB. It then fails after this with the following error:
> Task :search:publishRpmPublicationToIvyRepository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':search:publishRpmPublicationToIvyRepository'.
> Failed to publish publication 'rpm' to repository 'ivy'
> Could not write to resource 'http://myrepo/repository/myproject/myproject-1.23.4.noarch.rpm.sha1'.
> Could not PUT 'http://myrepo/repository/myproject/myproject-1.23.4.noarch.rpm.sha1'. Received status code 400 from server: Invalid path for a Yum repository
How can I prevent the .sha1 file to be uploaded? I only want the RPM to be uploaded (which is apparently the only thing allowed on this repo).
I also tried using maven-publish instead of ivy-publish but both give similar issues. maven-publish tries to upload a .pom with a similar failure.
I am able to upload the RPM fine manually using curl, but I would rather do it using Gradle plugins and standards.
My problem with build-info-extractor gralde plugin for artifactory
Source code with example for reproduce problem: https://github.com/lavcraft/gradle-artifactory-build-info-extractor-problems
Configure environment – artifactory_user artifactory_password artifactory_contextUrl
Run ./gradlew build aP
See jar artifacts properties in you artifactory instance
I expect, that this example (see below) works perfectly
artifactoryPublish {
properties = ['aa':'aaa']
properties {
nebula '**:**:**:*#*', 'not_added_prop':'sub0'
}
}
see sub0/build.gradle in github project
But it does not work. What is wrong with my example?
I think I found the cause of this issue.
Here's the artifactory closure configured in the build.gradle file, in the project you shared:
artifactory {
contextUrl = project.findProperty('artifactory_contextUrl')
publish {
repository {
repoKey = 'libs-snapshot-local'
username = project.findProperty('artifactory_user')
password = project.findProperty('artifactory_password')
}
defaults {
publications('nebula')
publishConfigs('archives')
publishIvy = false
properties {
nebula '*:*:*:*#*', 'want_to_add':'but not' // add only to *.pom artifacts. Why?
mavenJava commonProperties, '*:*:*:*#*'
}
}
}
}
As you can see above, the closure includes one publication (nebula) and one configuration (archives).
Running the build script as is prompts the following deployed artifacts:
$ gradle clean artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.pom
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.pom
Now, if you comment out the publication as follows:
//publications('nebula')
publishConfigs('archives')
You can the following:
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.jar
So it looks like both the archives configuration and the nebula publication contribute the same two artifacts above.
Since "want_to_add" property is configured on the nebula publication (and not on the archives publication), the 2 jars contributed by the configuration don't get the property.
A simple fix for this is issue is to remove the archives configuration:
publications('nebula')
//publishConfigs('archives')
Alternatively, if for some reason you do want to have both the configuration and publication, you can add the property to your configuration as well. Here's how you do this:
properties = ['want_to_add': 'but not']
So the full closure, with both the publication, configuration and properties for both is this:
defaults {
publications('nebula')
publishConfigs('archives')
publishIvy = false
properties = ['want_to_add': 'but not']
properties {
nebula '*:*:*:*#*', 'want_to_add':'but not' // add only to *.pom artifacts. Why?
mavenJava commonProperties, '*:*:*:*#*'
}
}
You can read more about this here:
https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin
I have some jar files in my local system which I wanted to publish using Gradle script but I could not find any solution till now.
I am able to publish artifacts which my build generates but I want to publish jars which are there in my local system.
I tried to declare the artifact something like following but it is throwing error:
publishing {
publications {
mavenJava(MavenPublication) {
artifact projJar
//This is jar file other than my built file which I want to upload (there are same files more in number to be uploaded):
artifact 'D:/myworkspace/Test/LocalJar.jar'
artifact source: projJar, classifier: 'src', extension: 'jar'
}
}
repositories {
maven {
credentials {
username 'user'
password 'password'
}
url "http://IP:Port/repository/RepoName/"
}
}
}
Error msg is:
*What went wrong:
Execution failed for task:publishMavenJavaPublicationToMaven2Repository'.
> Failed to publish publication 'mavenJava' to repository 'maven2'
> Invalid publication 'mavenJava': multiple artifacts with the identical extension and classifier ('jar', 'null').
Please guide me with some example how I can publish my local jar files to nexus repository (there are a lot of files there in my local which I want to publish)
Asking as a relative newbie to repo terminology and semantics:
I have a gradle project that builds a Spring-Boot jar file, and then runs an InstallAnywhere project file to package the jar as an installer for a Windows service. I need to publish the executable installer as a SNAPSHOT. I am using the gradle artifactory plugin (not the artifactory-publish plugin, only because I'm following the example of sister project).
The artifact is being published to the Maven snapshot repo, but the "-SNAPSHOT" placeholder is not being replaced by a timestamp. When I add the original Jar file to the artifacts to publish, the Jar file gets a timestamp added, but the .exe still does not. Relevant gradle code follows, and project version is set to "1.0.0-SNAPSHOT" in gradle.properties, along with other shown artifactory configuration properties:
task buildInstaller {
inputs.files cleanJarName.outputs
outputs.file installerFile
doLast {
project.exec {
workingDir 'InstallKit'
commandLine "${System.env.INSTALLANYWHERE_HOME}\\build.exe", 'MyInstallAnywhereProject.iap_xml', '-nupd'
}
}
}
artifactoryPublish {
dependsOn buildInstaller
}
configurations {
published
}
artifacts {
published installerFile
}
artifactory {
contextUrl = project.artifactoryContextUrl
publish {
repository {
repoKey = project.artifactoryPublishRepo
username = project.artifactoryUser
password = project.artifactoryPassword
}
defaults {
publishConfigs('published')
publishBuildInfo = true
publishArtifacts = true
publishPom = true
publishIvy = true
}
}
resolve {
repository {
repoKey = project.artifactoryResolveRepo
username = project.artifactoryUser
password = project.artifactoryPassword
maven=true
}
}
}
So why won't Artifactory properly snapshot an .exe? We were going to see if it was a limitation of Maven repos only handling Java-related types (jar, war, ear, etc.). So we looked at creating another Artifactory repo for binary snapshots using the generic(?) repo type, but the configuration screens do not offer the snapshot options present in the Maven repo configuration.
SNAPSHOT (actually Integration Revision) terminology is mandated by repository layouts.
Since Artifactory enforces single-typed repositories you are correct that a Maven repo will not handle the versioning of an .exe file.
Using a generic repo is the correct path to take - but you need to define your own folder and file integration revision to have Artifactory pick up on it.