Search code examples
javaazuregradleazure-artifacts

How to publish Gradle project to Azure Artifacts?


I am trying to publish a jar into Azure Artifacts using the command: ./gradlew publish. I am not running into any error. Gradle is making it look successful, even the stacktrace, looks like the publish command succeeded. But when I open Azure artifacts feed, there is nothing that connected to the feed. I also tried ./gradlew publishAllPublicationsToMyFeedRepository with the same result. Take the comments as multiple combinations of attempts I tried to get this to work:

build.gradle:

    plugins { 
        id 'java-library' apply true
        id "net.linguica.maven-settings" version "0.5" apply true
        id 'maven-publish' apply true
    }
    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
    }
    test {
        useJUnitPlatform()
    }
    jar {
        manifest {
            attributes('Main-Class': 'com.myapp.LanguageApp.SayHello')
        }
    }
    repositories {
        mavenCentral()
        mavenLocal()
        // maven {
        //     credentials {
        //      // I replaced the username with a PAT name, and password with PAT token
        //             username "username"
        //             password "password"
        //     }
        //     url 'https://pkgs.dev.azure.com/username/azure-artifacts/_packaging/MyFeed/maven/v1'
        //     name 'MyFeed'
        //     authentication {
        //         basic(BasicAuthentication)
        //     }
        // }
    }
    publishing {
        publications {}
        repositories {
            maven {
                url 'https://pkgs.dev.azure.com/username/azure-artifacts/_packaging/MyFeed/maven/v1'
                name 'MyFeed'
                // authentication {
                //     basic(BasicAuthentication)
                // }
                credentials {
                // I replaced the username with a PAT name, and password with PAT token
                    username "username"
                    password "password"
                }
            }
        }
    }

settings.gradle:

rootProject.name = 'gradle-project'

~/.m2/settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>MyFeed</id>
      /// yes, I replaced the username with a PAT name, and password with PAT token
      <username>username</username>
      <password>password</password>
    </server>
  </servers>
</settings>

Solution

  • So I will answer my own question. I was missing the group and version in the build.gradle. So gradle was actually successful in publishing my artifacts, it just needed the group and version to identify the specific artifact.

    group: thegroup
    version: theversion