Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Gradle plugin for managing authentication of upload and download tasks

Notifications You must be signed in to change notification settings

datlowe/gradle-maven-publish-auth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gradle plugin facilitating publishing to and dowloading form authenticated Maven repositories without adding credential information directly in the build file or in random properties files. Support for applying authentication information from Maven's settings.xml file is provided out-of-the-box.

Version 3.0.0 and later

Since version 3.0.0 of the original sebersole/gradle-maven-publish-auth this (datlowe) fork is not need any more. Everything is working the same as in datlowe version 2.0.2 (see below). Just use:

plugins {
  id "org.hibernate.build.maven-repo-auth" version "3.0.0" //or later version, if exists
}

Archiving this repository because it is not needed any more.

Version 2.0.2

This verison (datlowe fork) is just a slight modification of the original plugin, with the purse to be deployed to the plugins.gradle.org portal.

Applying plugin

To apply the plugin, simply specify:

plugins {
  id "org.datlowe.maven-publish-auth" version "2.0.2"
}

See also https://plugins.gradle.org/plugin/org.datlowe.maven-publish-auth

Example build script

plugins {
	id 'maven-publish'
	id "org.datlowe.maven-publish-auth" version "2.0.2"
}

repositories {
	maven {
		name = 'datlowe'
		url = 'https://some-priavte-repo.url/maven'
	}
}

group = 'org.datlowe'
version = '1.0-SNAPSHOT'

publishing {
	publications {
		testPub(MavenPublication) { artifactId "test_artifact" }
	}

	repositories {
		maven {
			name 'datlowe'
			url 'https://some-priavte-repo.url/maven'
		}
	}
}

defaultTasks 'publish'

Implementatation

The plugin class is org.hibernate.build.gradle.publish.auth.maven.AuthenticationManager, whose purpose is really just to create an instance each of

  • org.hibernate.build.gradle.publish.auth.maven.LegacyAuthenticationHandler
  • org.hibernate.build.gradle.publish.auth.maven.PublishingAuthenticationHandler

These handlers get attached to tasks of type org.gradle.api.tasks.Upload and org.gradle.api.publish.maven.tasks.PublishToMavenRepository, respectively.

But in either case, both ultimately delegate to any org.hibernate.build.gradle.publish.auth.maven.CredentialsProvider instances configured with the org.hibernate.build.gradle.publish.auth.maven.CredentialsProviderRegistry. Currently there is only one supported implementation, org.hibernate.build.gradle.publish.auth.maven.SettingsXmlCredentialsProvider which parses the Maven settings.xml file and makes those authentication credentials available to Gradle. This includes support for Maven "encrypted" passwords as outlined at http://maven.apache.org/guides/mini/guide-encryption.html.

By default, settings.xml is loaded from its default location (~/.m2/settings.xml). You can alter this by specifying -Dmaven.settings=your/path.

Support for the new Gradle Publication DSL

One of the new (and still ongoing and incubating) developments in Gradle is the new Publication DSL as the means for declaring how your project artifacts are published. See the Gradle UserGuide for more information.

The "bridge" between Maven authentication credentials and Gradle is the repository id. For an example, lets assume you have a Maven settings.xml that defines the following credentials:

<settings>
    <servers>
        <server>
            <id>dogdeball-repo</id>
            <username>average-joes</username>
            <password>dodgethis</password>
         </server>
    </servers>
</settings>

As you can see, we have credentials associated with a repository server with the identifier of "dogdeball-repo". This is the information we need supply in order for the plugin to make the connection. In the Publication DSL, this corelates to the name attribute of the repository configuration:

publishing {
    repositories {
        maven {
            name = 'dogdeball-repo'
            url 'http://repository.average.joes.com'
        }
    }
}

Support for legacy Gradle publishing (Upload task)

If you prefer to stick with the legacy publishing DSL, I have left support of that in place for the time being too. Again, the bridge is the repository id.

uploadArchives {
    repositories.mavenDeployer {
        ...
        repository(id: 'dogdeball-repo', url: 'http://repository.average.joes.com')
    }
}

Support for downloading artifacts

Plugin also allows to download artifacts from authenticated Maven repositories without adding credentials directly in build file. Again, the bridge is the repository id.

repositories {
    maven {
            name = 'dogdeball-repo'
            url 'http://repository.average.joes.com'
    }
}

Not supported

Currently plugin does not apply authentication information to buildscript repositories, so following won't work:

buildscript {
    repositories {
        maven {
            name = 'dogdeball-repo'
            url 'http://repository.average.joes.com'
        }
    }
}

About

Gradle plugin for managing authentication of upload and download tasks

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%