Skip to content

grossws/private-repo

Repository files navigation

Gradle private repo plugin

maven metadata.xml badge private repo

About

Gradle Settings plugin ws.gross.private-repo to configure private repository (Nexus, Artifactory) with sane defaults (for me).

Also contains these project plugins:

  • ws.gross.private-repo-publish plugin to configure maven-publish publishing repositories;

  • ws.gross.bootstrap-manifest to generate manifest files;

  • ws.gross.release-approve to add release approval task when nebula.release plugin present.

Supports Gradle 6.8+.

Configured via gradle properties (e.g. in ~/.gradle/gradle.properties).

Table 1. Configuration
Property Description Default Example

nexusUrl

Nexus base URL

 — 

https://nexus.example.com

nexusUsername

Nexus user name for repo

 — 

deploy-user

nexusPassword

Nexus user password for read access

 — 

some-secret-password

nexusRepo

Nexus repo or group to add

public

nexusExclusive

Use private repo as exclusive for groups and regexes

false

nexusGroups

Groups to exclude from Maven Central

empty

com.example,org.example

nexusGroupRegexes

Regexes for groups to exclude when searching Maven Central

derived from nexusUrl base domain

com\\.example(\\..*)?

nexusDefaultGroupRegex

Flag to enable generating default group regex from nexusUrl

true

nexusBootstrap

Comma-separated list of manifest GAV coordinates to add plugins and version catalogs

empty

com.example:bootstrap:1.0.0, com.example.platforms:platforms:1.5.0

nexusBootstrapCatalogs

Add version catalogs from bootstrap manifest

false

nexusReleasesRepo

Releases repo id for ws.gross.private-repo-publish plugin

releases

nexusSnapshotsRepo

Snapshots repo id for ws.gross.private-repo-publish plugin

snapshots

🔥
\ and : in gradle.properties requires escaping, so you have to use \\./\: instead of \./:
Effective additions to settings.gradle.kts
// Bootstrap manifest artifacts contains properties file with comma-separated plugin ids (`pluginIds` field), catalog (name=dependencyNotation pairs) and `version`.
// for manifest
//   catalogIds = commonLibs\=com.example.common\:catalog
//   pluginIds = com.example.first, com.example.second
//   version = 1.2
pluginManagement {
  repositories {
    gradlePluginPortal()

    maven {
      name = "nexus"
      url = uri("$nexusUrl/repository/$nexusRepo")
    }
  }

  plugins {
    // from manifest
    id("com.example.first") version("1.2")
    id("com.example.second") version("1.2")
  }
}

dependencyResolutionManagement {
  versionCatalogs {
    // for each catalog in manifest catalogIds
    create("commonLibs") { // from key
      from("com.example.common:catalog:1.2") // from value and version
    }
  }

  repositories {
    mavenCentral {
      groups.forEach { excludeGroup(it) }
      groupRegexes.forEach { excludeGroupByRegex(it) }
      // default exclude regex like `com\\.example(\\..*)?` is added if both `nexusGroups` and `nexusGroupRegexes` are empty
    }

    // when `nexusExclusive` not set or set to false
    maven {
      name = "nexus"
      url = uri("$nexusUrl/repository/$nexusRepo")

      // use `nexusUsername` and `nexusPassword` gradle properties to authenticate
      credentials {
        username = "$nexusUsername"
        password = "$nexusPassword"
      }
      authentication.create<BasicAuthentication>("basic")
    }

    // when `nexusExclusive` is set to true
    exclusiveContent {
      forRepository {
        maven {
          name = "nexus"
          url = uri("$nexusUrl/repository/$nexusRepo")

          // use `nexusUsername` and `nexusPassword` gradle properties to authenticate
          credentials {
            username = "$nexusUsername"
            password = "$nexusPassword"
          }
          authentication.create<BasicAuthentication>("basic")
        }
      }

      filter {
        groups.forEach { includeGroup(it) }
        groupRegexes.forEach { includeGroupByRegex(it) }
        // default include regex like `com\\.example(\\..*)?` is added if both `nexusGroups` and `nexusGroupRegexes` are empty
      }
    }
  }
}

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Gradle settings plugin to configure private repositories (Nexus/Artifactory)

Topics

Resources

License

Stars

Watchers

Forks