Gradle MavenPublication: "Task has not declared any outputs despite executing actions" - maven

I want to publish a zip archive to a remote maven repository. The task zipSources packs a sample file into a zip archive. The publication myPubliction publishes to mavenLocal and to the remote maven repository.
The publication works - I can see the packages uploaded to the remote repository. But the build still fails with
> Task :publishMyPublicationPublicationToMavenRepository FAILED
Task ':publishMyPublicationPublicationToMavenRepository' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Publishing to repository 'maven' (null)
FAILURE: Build failed with an exception.
What am I missing? How do I declare outputs for the publishing action? Or is there another cause?
Here is my build.gradle:
plugins {
id "maven-publish"
}
group = 'com.example.test'
version = '0.0.1-SNAPSHOT'
task zipSources(type: Zip, group: "Archive", description: "Archives source in a zip file") {
from ("src") {
include "myfile.txt"
}
into "dest"
baseName = "helloworld-demo"
destinationDir = file("zips")
}
publishing {
publications {
myPublication(MavenPublication) {
artifactId = 'my-library'
artifact zipSources
pom {
name = 'My Library'
description = 'A concise description of my library'
}
}
}
repositories {
maven {
mavenLocal()
}
maven {
url "http://nexus.local/content/repositories/snapshots"
credentials {
username = 'admin'
password = 'admin'
}
}
}
}

It appears there must not be a mavenLocal() declaration inside repositories, as per https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:install

Related

How do I publish file created by zip task in gradle

I'd like to publish the output of my custom zip task to a maven repo. My problem is that when I set the artifact of the publication as the zip task, the file that gets zipped is not what gets published. Instead what gets published is the value given to the "from" argument of my custom zip task. How would I make it so that "jar.zip" is the file that is published?
tasks.register('zipJars', Zip) {
archiveFileName = "jar.zip"
destinationDirectory = layout.buildDirectory.dir("${projectDir.parentFile}/DesktopAndroid/jars/zipped")
from fatJarDev
}
publishing {
publications {
apkBuilding(MavenPublication){
artifact zipJars
}
}
repositories {
maven {
name = 'Local'
url = "file://${rootDir}/Repository"
}
}
}```
Ah - are you referring to the name of the file in the maven repo ? you will need to customise it in publication ;
see https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html
publishing {
publications {
apkBuilding(MavenPublication){
artifact zipJars
artifactId 'zipjars'
}
}
repositories {
maven {
name = 'Local'
url = "file://${rootDir}/Repository"
}
}
}

How do I suppress POM and IVY related warnings in Gradle 7?

After upgrading to Gradle 7 I have many warnings like:
Cannot publish Ivy descriptor if ivyDescriptor not set in task ':myProject:artifactoryPublish' and task 'uploadArchives' does not exist.
Cannot publish pom for project ':myProject' since it does not contain the Maven plugin install task and task ':myProject:artifactoryPublish' does not specify a custom pom path.
The artifactoryPublish task works fine.
My Gradle script:
buildscript {
repositories{
maven {
url = '...'
credentials {
username '...'
password '...'
}
metadataSources {
mavenPom()
artifact()
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.24.12"
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
suppressAllPomMetadataWarnings()
}
}
}
group = '...'
artifactory {
contextUrl = '...'
publish {
repository {
repoKey = '...'
username = '...'
password = '...'
}
defaults {
publishConfigs('archives')
publishIvy = false
publications("mavenJava")
}
}
}
How do I disable those warnings?
It looks like you mixed between the old Gradle publish-configuration method and the new Gradle publication method.
You applied the maven-publish plugin which allows creating publications. In artifactory.default, you added the "mavenJava" publication as expected.
However, the archives publish-configuration doesn't exist in your build.gradle file. Basically, publish-configurations are created by the legacy maven plugin. The configured mavenJava publication does the same as the archives publish-configuration and therefore all of the JARs are published as expected.
To remove the warning messages you see, remove the publishConfigs('archives') from artifactory.default clause:
artifactory {
publish {
defaults {
publishConfigs('archives') // <-- Remove this line
publishIvy = false
publications("mavenJava")
}
}
}
Read more:
Gradle Artifactory plugin documentation
Example

Artifact is not published using gradle and artifactory plugin

I'm trying to upload a simple zip to artifactory using gradle. This is my script:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def user = "$System.env.ARTIFACTORY_USER"
def pass = "$System.env.ARTIFACTORY_PASSWORD"
task createArchive(type: Zip){
baseName 'myzip'
destinationDir(new File('target'))
from '.'
exclude 'target'
exclude '.gradle'
exclude 'build.gradle'
exclude 'README.md'
doFirst{
new File('target').mkdirs()
}
}
task clean(type: Delete){
delete 'target'
}
publishing {
publications {
customArtifact(MavenPublication) {
artifact createArchive
}
}
}
artifactory {
publish {
contextUrl = 'http://myrepo/artifactory'
repository {
repoKey = "myrepo-tools"
username = user
password = pass
}
publications ('customArtifact')
}
}
The code seems to work fine but actually only the build info are published. The zip is not:
Deploying build descriptor to: http://myrepo/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://myrepo/artifactory/webapp/builds/myproject/1503338121156
My code does not seem different from the one published here: How to build Groovy JAR w/ Gradle and publish it to in-house repo (which was pointed as reference in question nothing published to artifactory using gradle artifactory plugin) but I'm not sure that is still valid since is quite old.
The main difference is that almost all the examples are using java plugin so they have the from components.java line in the publications. In my case I cannot use it as I have a custom zip.. but I can't find what else can be changed.
Thanks,
Michele.

gradle artifactory plugin fails to publish with groupID

In my build.gradle script, publishing works when the groupId is left undefined. I would like to use "org.company.foobar.common" for the groupId.
When I uncomment the groupId lines in the following build.gradle script, I receive an error. Below the script is the execution results when this groupId is defined.
buildscript {
repositories {
maven { url "http://tribe.ust.doj.gov:8085/artifactory/jcenter/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/MavenCentral/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/gradlePlugins/"}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
repositories {
maven { url "http://tribe.ust.doj.gov:8085/artifactory/jcenter/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/MavenCentral/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/gradlePlugins/"}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
def getArtifactoryUrl() {
return "http://tribe.ust.doj.gov:8085/artifactory/"
}
allprojects {
repositories {
def artifactoryMcentralUrl = getArtifactoryUrl() + "MavenCentral/"
maven {url artifactoryMcentralUrl }
}
}
dependencies {
}
sourceSets {
main {
java {
srcDir "/src"
}
}
}
//project.group = 'org.company.foobar.common'
task printProps {
doLast {
println artifactory_user
println artifactory_contextUrl
//println project.group
}
}
publishing {
publications {
mavenJava(MavenPublication) {
//groupId project.group
artifactId project.getName()
version '1.0.0'
from components.java
}
}
}
artifactory {
def artifactoryUrl = getArtifactoryUrl()
contextUrl = artifactoryUrl
publish {
repository {
repoKey = 'libs-snapshot-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publications('mavenJava')
publishArtifacts = true
publishPom = true
}
}
}
The output from "gradle artifactoryPublish" when using the groupId (uncommented) is:
$ gradle artifactoryPublish
:generatePomFileForMavenJavaPublication
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:artifactoryPublish
Deploying artifact: http://tribe.ust.doj.gov:8085/artifactory/libs-snapshot-local/org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar
:artifactoryPublish FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':artifactoryPublish'.
> java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors:
The repository 'libs-snapshot-local' rejected the resolution of an artifact 'libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar' due to conflict in the snapshot release handling policy. Status code: 409
* 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: 1.84 secs
As it seems, you are trying to publish a RELEASE artifact to a SNAPSHOT repository. When using maven repositories in Artifactory, you will need to make sure that you are following both the Maven layout, and the release / snapshot policy.
In this specific example it seems that your issue is as following:
Artifactory, following maven policy, is recognizing the following path:
'libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar' as a release, while the repository is set to handle only snapshots. For this specific path to work, and in case this is really a snapshot artifact, you will need to change the path to be:
libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0-SNAPSHOT/kambucha-1.0.0-SNAPSHOT.jar
If this is a release, change your deployment path to use 'libs-release-local' repository
You can read more on the repository configuration here

Publishing custom artifact built from task in gradle

I am having some issues trying to create a task that build a special file which is then uploaded to artifactory.
Heres a simplified version:
apply plugin: 'maven-publish'
task myTask {
ext.destination = file('myfile')
doLast {
// Here it should build the file
}
}
publishing {
repositories {
maven {
name 'ArtifactoryDevDirectory'
url 'http://artifactory/artifactory/repo-dev'
credentials {
username 'username'
password 'password'
}
}
}
publications {
MyJar(MavenPublication) {
artifactId "test"
version "1.0"
groupId "org.example"
artifact myTask.destination
}
}
}
This works, except that gradle publish does not run myTask. I tried adding
publishMyJarPublicationToArtifactoryDevDirectoryRepository.dependsOn myTask
but i just get:
Could not find property 'publishMyJarPublicationToArtifactoryDevDirectoryRepository' on root project 'test'.
I tried messing about with the artifact, adding a custom artifact and configuration and publishing that instead but that did not work either.
Any help would be greatly appreciated.
afterEvaluate {
publishMyJarPublicationToArtifactoryDevDirectoryRepository.dependsOn myTask
}
Accomplishes what I want.

Resources