How can gradle use repository settings from maven's settings.xml to publish artifacts to a repository?


(Peter Kahn) #1

Problem: Want gradle to build (a custom plugin) and publish it to my internal artifact repository without hard coding credentials in my build.gradle file


Qualifying name for maven-publish-auth plugin
Deploy to Internal Maven Repo without hardcoding credentials
Gradle and maven-publis-auth issue
(Peter Kahn) #2

To do this we need to * have maven settings.xml file configured properly * enable maven-publish * enable maven-publish-auth ** set buildscript dependencies and repositories to fine auth

  • configure maven publish

We enable the two plugins and add auth plugin + repository info to the build script’s environment

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'maven-publish-auth'
  buildscript {
  dependencies {
    classpath 'org.hibernate.build.gradle:gradle-maven-publish-auth:2.0.1'
  }
      repositories {
    maven {
      url "http://repository.jboss.org/nexus/content/groups/public/"
    }
    mavenLocal()
    mavenCentral()
  }
}

Define the publishing section so we can publish and add in the name + url of a repository from the maven settings.xml

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
  repositories {
  maven {
    name "snapshots"
    url "http://my-private-repository.myco.com/nexus/content/repositories/snapshots"
  }
}

$HOME/.m2/settings.xml

<settings>
  <servers>
    <server>
      <id>snapshots</id>
      <username>mysnapuser</username>
      <password>snap password</password>
    </server>
    ...
  </servers>
</settings>

Passing the location of the Maven settings.xml file to Maven Publish