gradle publish does not pick up artifacts: "Task has not declared any outputs despite executing actions." - gradle

I'm migrating a java project from gradle 2.x to 5.3.1.
The last problem is that no artefacts (a tar in our case) are published to artifactory.
The config in main build.gradle is
subprojects {
apply plugin: "com.jfrog.artifactory"
project.ext {
artifactoryConfig = new File(project.gradle.gradleUserHomeDir, "artifactory.gradle")
}
if (artifactoryConfig.exists()) {
apply plugin: 'maven'
apply from: artifactoryConfig
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url $OUR_ARTIFACTORY }
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
}
artifactory {
publish {
contextUrl = "${artifactoryBaseUrl}"
repository {
repoKey = "libs-release-local"
username = "${artifactoryUsername}"
password = "${artifactoryPassword}"
}
}
resolve {
repoKey = 'repos'
}
}
And in the module
task('dist', type: Tar) {
dependsOn('jar')
archiveName "$MODULE-${version}.${extension}"
...
}
publishing {
publications {
mavenJava(MavenPublication)
{
artifact dist {
}
}
}
}
configurations.archives.artifacts.clear()
artifacts {
archives dist
}
Now when I do ./gradlew --info :$MODULE:artifactoryPublish it complains about missing outputs and does not publish the tar to artifactory.
How to fix this?
> Task :$MODULE:artifactoryPublish
Task ':$MODULE:artifactoryPublish' is not up-to-date because:
Task has not declared any outputs despite executing actions.
:$MODULE:artifactoryPublish (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
:artifactoryDeploy (Thread[Execution worker for ':',5,main]) started.
> Task :artifactoryDeploy
Task ':artifactoryDeploy' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Deploying build descriptor to: $OUR_ARTIFACTORY/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under $OUR_ARTIFACTORY/artifactory/webapp/builds/$MODULE/1554465369336
:artifactoryDeploy (Thread[Execution worker for ':',5,main]) completed. Took 0.155 secs.

Turns out the solution was to add
artifactoryPublish {
publications('mavenJava')
}

For me the problem was that the url and credentials were null. It resulted in the same error message(Task has not declared any outputs).
artifactory {
contextUrl = artifactoryUrl
publish {
repository {
username = artifactoryPublishUser
password = artifactoryPublishPassword

The most valuable hint is a running example
https://github.com/jfrog/project-examples/tree/master/gradle-examples/gradle-android-example

Related

publish pre-built jars to nexus repo using gradle

I am trying to publish obfuscated jars to nexus repo.
I created a task to obfuscate the code using proguard, then a task that copy the obfuscated jars into build folder.
task proguard (type: proguard.gradle.ProGuardTask) {
println("Performing Obfuscation ..")
configuration 'proguard.conf'
subprojects { porject ->
injars "${projectDir}/build/libs/${porject.name}-${rootProject.version}.jar"
outjars "${projectDir}/build/libs/obfuscated/${porject.name}-${rootProject.version}.jar"
}
libraryjars "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar"
}
task postProguard (){
doFirst{
println("Deleting Non Obfuscated jars")
subprojects { project ->
delete "${projectDir}/build/libs/${project.name}-${rootProject.version}.jar"
}
println("Copying Obfuscated Jars")
subprojects { project ->
copy {
from "${projectDir}/build/libs/obfuscated/"
into "${projectDir}/build/libs/"
include '*.jar'
}
}
}
}
proguard.finalizedBy postProguard
the issue is when I run ./gradlew publish the project gets re-built and the jars gets changed to non obfuscated again.
I tried to change the publishing task but without results.
publishing {
if(new File("${projectDir}/build/libs/obfuscated").exists()){
publications {
maven(MavenPublication) {
artifact "${projectDir}/build/libs/${project.name}-${rootProject.version}.jar"
pom.withXml {
def dependency = asNode().appendNode('dependencies').appendNode('dependency')
dependency.appendNode("groupId", "${project.name}")
dependency.appendNode("artifactId", "${project.name}")
dependency.appendNode("version", "${rootProject.version}")
}
}
}
}
repositories {
maven {
name = 'maven-snapshots'
url = ***
}
}
}
I added a builtBy attribute to the publication here is a working code
publications {
if(new File("${projectDir}/build/libs/obfuscated").exists()){
maven(MavenPublication) {
artifact ("${projectDir}/build/libs/${project.name}-${rootProject.version}.jar"){
builtBy postProguard
}
}
}
}

Gradle Error when using maven publishing task

I am using Gradle version 6.7.1, Currently, in my application I facing an issue with the maven publishing task.
We have kept the publishing task in the central location Gradle file named ( nexusgradle-1.0.5.gradle) and importing it via apply from
the content of the central location Gradle (nexusgradle-1.0.5.gradle) is the below which contain the information of nexus repo for snapshot and release along with user credentials for pushing artefacts to nexus.
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
from components.web
}
}
repositories {
maven {
credentials {
username 'uploader'
password 'uploaderpassword'
}
println 'A message which is logged at QUIET level'
name 'Nexus_Repo'
def releasesRepoUrl = 'http://<hostname>/repository/<maven-releases>/'
def snapshotsRepoUrl = 'http://<hostname>/repository/<maven-snapshots>/'
url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
The application Gradle ( child Gradle file) looks like the one below
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'war'
// Add git release plugin for versioning snaphots and release builds
id 'pl.allegro.tech.build.axion-release' version '1.10.1'
id 'org.springframework.boot' version '2.1.4.RELEASE'
// Add Git properties plugin.
id 'com.gorylenko.gradle-git-properties' version '2.2.0'
id 'jacoco'
}
// apply from center location
apply from :'http://<hostaname>/repository/thirdparty/com/mf/nexusgradle/1.0.5/nexusgradle-1.0.5.gradle'
repositories {
maven {
url = 'http://<hostname>/repository/groupRepo/'
}
jcenter()
}
test {
testLogging.showStandardStreams = true
maxParallelForks = 3
ignoreFailures = true // to skip test Failures
testLogging { //logging the test
exceptionFormat = 'full'
events "passed", "skipped", "failed"
}
}
jacoco {
toolVersion = '0.8.3'
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled true //enabling for generate xml for to capture data in sonarqube server
}
}
// Customize Git properties plugin.
gitProperties {
// Change date format in git.properties file.
dateFormat = "yyyy-MM-dd HH:mm:ssZ"
dateFormatTimeZone = 'GMT'
}
dependencies {
implementation 'org.springframework.boot:spring-boot:2.1.4.RELEASE'
// mutliple import below
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
scmVersion {
repository {
directory = project.rootProject.file('.')
}
}
group = 'com.package'
description = 'appname'
project.version = scmVersion.version
project.ext.timestamp = new Date().format("dd/MM/yyyy HH:mm:ss")
processResources {
filter ReplaceTokens, tokens:[BUILD_VERSION: project.version, BUILD_TIMESTAMP: project.ext.timestamp]
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
war {
enabled = true
}
springBoot {
buildInfo()
}
bootWar {
archiveClassifier = 'boot'
mainClassName = 'com.package.appname.SpringBootRunner'
}
when I run the Gradle command for publishing
gradlew clean build publish
The task will fail as the publishing task will try to push artefacts of the snapshot to the release repo instead of the snapshot repo.
> Configure project :
A message which is logged at QUIET level
> Task :clean UP-TO-DATE
> Task :bootBuildInfo
> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :generateGitProperties
> Task :processResources
> Task :classes
> Task :bootWar
> Task :war
> Task :assemble
> Task :check
> Task :build
> Task :generateMetadataFileForMavenJavaPublication
> Task :generatePomFileForMavenJavaPublication
> Task :publishMavenJavaPublicationToNexus_RepoRepository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToNexus_RepoRepository'.
> Failed to publish publication 'mavenJava' to repository 'Nexus_Repo'
> Could not PUT 'http://<hostname>/repository/maven-releases/com/package/appname/1.0.9-SNAPSHOT/maven-metadata.xml'. Received status code 400 from server: Repository version policy: RELEASE does not allow metadata in path: com/package/appname/1.0.9-SNAPSHOT/maven-metadata.xml
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
But if I remove the apply from: item and bring the Publishing task to the application Gradle ( child Gradle file) file it will work fine, the build artefact is pushed to snapshot repo without any issue.
> Configure project :
A message which is logged at the QUIET level
> Task :clean UP-TO-DATE
> Task :bootBuildInfo
> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :generateGitProperties
> Task :processResources
> Task :classes
> Task :bootWar
> Task :war
> Task :assemble
> Task :check
> Task :build
> Task :generateMetadataFileForMavenJavaPublication
> Task :generatePomFileForMavenJavaPublication
> Task :publishMavenJavaPublicationToNexus_RepoRepository
> Task :publish
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 29s
10 actionable tasks: 9 executed, 1 up-to-date
Can someone guide me, what mistake I am making when putting the maven publishing task in a parent Gradle file? why child Gradle cant resolve values from parent properly
I found a way to fix it by updating the content of the central Gradle /parent file (nexusgradle-1.0.5.gradle) by adding
afterEvaluate
with the modification, it worked fine.
Is it the correct approach? or is there any better way to do it?
apply plugin: 'maven-publish'
afterEvaluate {project ->
publishing {
publications {
mavenJava(MavenPublication) {
from components.web
}
}
repositories {
maven {
credentials {
username 'uploader'
password 'uploaderpassword!'
}
name 'Nexus_Repo'
def releasesRepoUrl = 'http://<hostname>/repository/<maven-releases>/'
def snapshotsRepoUrl = 'http://<hostname>/repository/<maven-snapshots>/'
url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
}

Gradle uploadArchives publishes POM twice

Gradle tries to publish maven's POM twice (through uploadArchives task)
I have multiproject build with apply from:s where specified how to publish my artifacts (publish-jars.gradle):
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
build.dependsOn(sourcesJar)
artifacts {
archives sourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'releases repo') {
authentication(
userName: rootProject.properties.get('artifactory.username'),
password: rootProject.properties.get('artifactory.token')
)
}
snapshotRepository(url: 'snapshots repo) {
authentication(
userName: rootProject.properties.get('artifactory.username'),
password: rootProject.properties.get('artifactory.token')
)
}
}
}
}
def installer = install.repositories.mavenInstaller
def deployer = uploadArchives.repositories.mavenDeployer
[installer, deployer]*.pom*.whenConfigured { pom ->
pom.project {
packaging 'jar'
}
pom.withXml {
asNode().dependencies.'*'.each {
if (it.scope*.value != null) {
it.scope*.value = 'compile'
}
}
asNode().dependencyManagement.dependencies.'*'.each {
if (it.scope*.value != null) {
it.scope*.value = 'compile'
}
}
def repos = asNode().appendNode('repositories')
project.repositories.findAll { it.name != 'MavenLocal' }.each {
def repo = repos.appendNode('repository')
repo.appendNode('id', it.name)
repo.appendNode('name', it.name)
repo.appendNode('url', it.url)
}
}
if (project.hasProperty('pomConfigurer')) {
pom.withXml(pomConfigurer)
}
}
install.dependsOn build
uploadArchives.dependsOn build
task 'publish-snapshot'() {
dependsOn uploadArchives
}
task publish() {
dependsOn uploadArchives
}
and I have module which contains only parent pom (:my-project:parent):
dependencyManagement {
generatedPomCustomization {
enabled = true
}
}
ext.pomConfigurer = {
// some pom configuration
}
and finally I have root project build.gradle:
allprojects {
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
}
subprojects {
apply from: file('publish-jars.gradle')
}
Is it gradle bug, or am I doing something wrong?
UPD: Gradle output
> Task :my-project:some-module:compileKotlin
> Task :my-project:some-other-module:compileKotlin
> Task :my-project:some-another-module:compileKotlin
> Task :my-project:some-yet-another-module:compileKotlin
> Task :my-project:one-more-module:compileKotlin
> Task :my-project:last-module:compileTestKotlin
> Task :mkGitTag
##teamcity[setParameter name='env.release_tag' value='v2.1.1-rc20']
> Task :my-project:parent:uploadArchives
Could not transfer artifact groupname:parent:pom:2.1.1-rc20 from/to remote (https://releases repo): Failed to transfer file: https://releases repo/groupname/parent/2.1.1-rc20/parent-2.1.1-rc20.pom. Return code is: 409, ReasonPhrase: Conflict.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':my-project:parent:uploadArchives'.
> Could not publish configuration 'archives'
> Failed to deploy artifacts: Could not transfer artifact groupname:parent:pom:2.1.1-rc20 from/to remote (https://releases repo): Failed to transfer file: https://releases repo/groupname/parent/2.1.1-rc20/test-parent-2.1.1-rc20.pom. Return code is: 409, ReasonPhrase: Conflict.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
43 actionable tasks: 43 executed

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

"gradle publish" wrongly reporting up-to-date

I'm trying to build Apache S4 and publish it to our Nexus repository. gradle publishToMavenLocal worked, so I added
publishing {
repositories {
maven {
credentials {
username "admin"
password "admin123"
}
url "http://127.0.0.1:9081/nexus/content/repositories/releases/"
}
}
}
to build.gradle after apply plugin: 'maven-publish'. This worked for other projects on the same machine. However, now I get
aromanov#ws:~/etc/apache-s4-0.6.0$ gradle clean publish
Build file '/home/aromanov/etc/apache-s4-0.6.0/subprojects/s4-benchmarks/s4-benchmarks.gradle': line 42
The RepositoryHandler.mavenRepo() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the maven() method instead.
Runs Apache RAT. Exclusions are defined in .rat-excludes fileUNDEFINED
:clean
:s4-base:clean
:s4-benchmarks:clean
:s4-comm:clean
:s4-core:clean
:s4-tools:clean
:test-apps:clean
:test-apps:consumer-app:clean
:test-apps:producer-app:clean
:test-apps:simple-deployable-app-1:clean
:s4-base:publish UP-TO-DATE
:s4-benchmarks:publish UP-TO-DATE
:s4-comm:publish UP-TO-DATE
:s4-core:publish UP-TO-DATE
:s4-tools:publish UP-TO-DATE
:test-apps:publish UP-TO-DATE
:test-apps:consumer-app:publish UP-TO-DATE
:test-apps:producer-app:publish UP-TO-DATE
:test-apps:simple-deployable-app-1:publish UP-TO-DATE
BUILD SUCCESSFUL
Total time: 10.468 secs
Using gradle -i I get
Selected primary task 'publish'
Tasks to be executed: [task ':s4-base:publish', task ':s4-benchmarks:publish', task ':s4-comm:publish', task ':s4-core:publish', task ':s4-tools:publish', task ':test-apps:publish', task ':test-apps:consumer-app:publish', task ':test-apps:producer-app:publish', task ':test-apps:simple-deployable-app-1:publish']
:s4-base:publish (Thread[main,5,main]) started.
:s4-base:publish
Skipping task ':s4-base:publish' as it has no actions.
:s4-base:publish UP-TO-DATE
:s4-base:publish (Thread[main,5,main]) completed. Took 0.005 secs.
... so on for other subprojects
There is no output at the Nexus repository. How can I fix this?
UPDATE: if I use configuration from chapter 51 of the User Guide, replacing ivy by maven:
uploadArchives {
repositories {
maven {
credentials {
username "admin"
password "admin123"
}
url "http://127.0.0.1:9081/nexus/content/repositories/releases/"
}
}
}
then upload works, but it uploads jars and ivy.xml, without POMs. With config from Chapter 52:
configurations {
deployerJars
}
dependencies {
deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
uploadArchives {
configuration = configurations.deployerJars
repositories {
mavenDeployer {
repository(url: "http://127.0.0.1:9081/nexus/content/repositories/releases/") {
authentication(userName: "admin", password: "admin123")
}
}
}
}
I get
aromanov#ws:~/etc/apache-s4-0.6.0$ gradle -i upload
Starting Build
Starting file lock listener thread.
...
Publishing configuration: configuration ':s4-base:deployerJars'
Publishing to repository 'mavenDeployer'
[ant:null] Error reading settings file '/tmp/gradle_empty_settings2934509160228124339.xml' - ignoring. Error was: /tmp/gradle_empty_settings2934509160228124339.xml (No such file or directory)
:s4-base:uploadArchives (Thread[main,5,main]) completed. Took 1.113 secs.
...
The complete build script.
If no any action found, it will mark as up to date .
I am using gradle 2.4 and this is working like a charm
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
credentials {
username 'admin'
password 'password'
}
url "http://baseUrl/artifactory/libs-release-local"
}
}
}
you need to provide publish repositories and publications.

Resources