Maven publish plugin complains no username provided but its there - gradle

I am trying to push a jar to artifactory, i get the following error from the gradle script:
But the username is there, is hardcoded to "aws":
publishing {
publications {
publicMyArtifact(MavenPublication) {
groupId "com.company.project"
artifactId "artifact"
version = "1.0"
afterEvaluate {
artifact "repo/path/*.jar"
}
}
}
repositories {
maven {
name "reponame"
url "https://accountnumber.d.codeartifact.eu-central-1.amazonaws.com/maven"
credentials {
username = "aws"
password = System.getenv("CODEARTIFACT_AUTH_TOKEN")
}
}
}
}
I invoke this task with the following line in jenkins: sh "./gradlew publish"
Any idea what could be possibly the reason?

Related

maven publish artifacts to local repository fail

I would like to test my publish task locally first before deploy it to maven server. I wish it can be deploy to local maven repository as below but it doesn't work
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
name 'release'
url "/home/user/.m2/repository"
credentials {
username = ""
password = ""
}
}
}
publications {
deployApp(MavenPublication) {
groupId "com.sample"
artifactId "demo"
version "1.0.0"
artifact ("demo.apk")
}
}
}
What's the proper way to verify publish task locally?
to locally publish you just need
publishing {
publications {
mavenJava(MavenPublication) {
artifact bootJar //replace with your artefact
}
}
}
it defaults to /Users/username/.m2/repository
remove your repositories section

Configure description for package published to the GitHub Packages Gradle registry

When publishing a package to the GitHub Packages Gradle registry, the resulting package's description is empty.
Is it possible to set the package description via config?
I have the following (abridged) configuration in build.gradle.kts, I was assuming it would use pom.description or the repo's README.md as the description but that doesn't seem to be the case.
plugins {
`maven-publish`
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = project.group.toString()
artifactId = rootProject.name
version = project.version.toString()
from(components["java"])
pom {
name.set("steam-webapi-kt")
description.set("Steam WebAPI wrapper in Kotlin and Ktor")
url.set("https://github.com/j4ckofalltrades/steam-webapi-kt")
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/j4ckofalltrades/steam-webapi-kt")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
Sample package: https://github.com/j4ckofalltrades/steam-webapi-kt/packages/899640

In build.gradle how to extract and reuse Maven repository configuration?

I've got this build.gradle file:
repositories {
maven {
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
url 'http://some.domain/artifactory/repo'
}
}
publishing {
repositories {
publications {
maven(MavenPublication) {
from components.java
}
}
maven {
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
url 'http://some.domain/artifactory/repo'
}
}
}
I want to extract and reuse the Maven repository definition.
This is not working:
repositories {
mavenRepository()
}
publishing {
repositories {
publications {
maven(MavenPublication) {
from components.java
}
}
mavenRepository()
}
}
private void mavenRepository() {
maven {
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
url 'http://some.domain/artifactory/repo'
}
}
It results in
Could not find method mavenRepository() for arguments [gradle-dev] on
repository container of type
org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.
How can I achieve this goal?
lets say you have a separate repositories.gradle file and name your maven repo..
maven {
name 'myrepo'
url 'https://xxxx'
credentials {
username = System.getenv("xxx") ?: "${xxx}"
password = System.getenv("xxx") ?: "${xxx}"
}
}
maven { name 'anotherrepo' }
then at root project level you can run:
apply from: "$rootDir/gradle/repositories.gradle"
This will populate repositories with all repos. Then to use populate a specific one somehwere else, you can use:
repositories.add(rootProject.repositories.getByName('myrepo'))
I found the answer on this blog page: https://themightyprogrammer.dev/snippet/reusing-gradle-repo
thanks to mightprogrammer!

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

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

Gradle publish repository defaults or ignores

I have defined multiple repositories to publish to, but want the "gradle publish" job only to deploy to some of them.
E.g. in the following configuration I want that a "gradle publish" deploys the artifact to repo_a and repo_b but NOT repo_c.
A deploy to repo_c should only be done when the publishMavenJavaPublicationToRepo_cRepositoryjob is activated.
Is that somehow possible?
Thanks
publishing {
repositories {
maven {
url "https://repo_a/maven-releases/"
credentials {
username 'xxx'
password 'xxx'
}
name "repo_a"
}
maven {
url "https://repo_b/maven-releases/"
credentials {
username 'xxx'
password 'xxx'
}
name "repo_b"
}
maven {
url "https://repo_c/maven-releases/"
credentials {
username 'xxx'
password 'xxx'
}
name "repo_c"
}
}
publications {
mavenJava(MavenPublication) {
....
}
}
}
You can try the following code snippet to disable your publishMavenJavaPublicationToRepo_cRepository publishing task (reference):
afterEvaluate {
tasks.withType(PublishToMavenRepository) { task ->
if (task.repository.name == "repo_c") {
task.enabled = false
task.group = null
}
}
}

Resources