gradle-maven-settings-plugin

Gradle Maven settings plugin

Home: github.com/comahe-de/gradle-maven-settings-plugin

Overview

This Gradle plugin provides a migration path for projects coming from a Maven ecosystem. It exposes standard Maven configuration located in settings files to your Gradle project. This allows projects to continue to leverage functionality provided by Maven such as mirrors as well use existing settings configuration to store encrypted repository authentication credentials.

Hint

This is a fork of https://github.com/mark-vieira/gradle-maven-settings-plugin.

It was transferred to Kotlin and dependencies were updated.

New features are

Usage

This plugin is hosted on the Gradle Plugin Portal. To use the plugin, add the following to your build.gradle.kts file.

plugins {
  id ("de.comahe.maven-settings") version "0.1.0"
}

To load also plugins from your private repositories you have to apply the plugin in the settings.gradle.kts. There, the plugin declaration must be done after the pluginManagement block, e.g.

rootProject.name = "myProject"

pluginManagement {
    repositories {
        mavenLocal()
        gradlePluginPortal()
    }
}

plugins {
    id("de.comahe.maven-settings") version "0.1.0"
}

Mirrors

The plugin exposes Maven-like mirror capabilities. The plugin will properly register and enforce any mirrors defined in a settings.xml with <mirrorOf> values of *, external:* or central. Existing repositories {...} definitions that match these identifiers will be removed.

Exclusions are also taken into consideration. For example, a <mirrorOf> value of *,!myRepo will replace all repositories except for the repository with the name ‘myRepo’.

Credentials

The plugin will attempt to apply credentials located in <server> elements to appropriate Maven repository definitions in your build script. This is done by matching the <id> element in the settings.xml file to the name property of the repository definition.

repositories {
    maven {
        name = "myRepo" // should match <id>myRepo</id> of appropriate <server> in settings.xml
        url = "https://intranet.foo.org/repo"
    }
}

Server credentials are used for mirrors as well. When mirrors are added the plugin will look for a <server> element with the same <id> and the configured credentials are used and decrypted if necessary.

Publishing

The plugin will also attempt to apply credentials to repositories configured using the ‘maven-publish’ plugin.

publishing {
    repositories {
        maven {
            name = "myRepo" // should match <id>myRepo</id> of appropriate <server> in settings.xml
            url = "https://intranet.foo.org/repo/repositories/releases"
        }
    }
}

Note: Currently only Basic Authentication using username and password is supported at this time.

Profiles

Profiles defined in a settings.xml will have their properties exported to the Gradle project when the profile is considered active. Active profiles are those listed in the <activeProfiles> section of the settings.xml, the activeProfiles property of the mavenSettings {...} configuration closure, or those that satisfy the given profile’s <activation> criteria.

Repositories of active profiles defined in the settings.xml are automatically added to the project repositories.

Configuration

Configuration of the Maven settings plugin is done via the mavenSettings {...} configuration closure. The following properties are available.