From 48d6d0989279ee254af589c00b5a4af961e0fc83 Mon Sep 17 00:00:00 2001 From: Marcus Hert Da Coregio Date: Tue, 23 Jan 2024 08:51:54 -0300 Subject: [PATCH] Allow Env vars to determine Artifactory Properties Closes gh-2754 --- .../convention/ArtifactoryPlugin.groovy | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy index 4412a868..afee77b9 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * 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 @@ -13,7 +13,6 @@ * License for the specific language governing permissions and limitations under * the License. */ - package io.spring.gradle.convention import org.gradle.api.Plugin @@ -22,23 +21,50 @@ import org.gradle.api.publish.maven.plugins.MavenPublishPlugin class ArtifactoryPlugin implements Plugin { + private static final String ARTIFACTORY_URL_NAME = "ARTIFACTORY_URL" + + private static final String ARTIFACTORY_SNAPSHOT_REPOSITORY = "ARTIFACTORY_SNAPSHOT_REPOSITORY" + + private static final String ARTIFACTORY_MILESTONE_REPOSITORY = "ARTIFACTORY_MILESTONE_REPOSITORY" + + private static final String ARTIFACTORY_RELEASE_REPOSITORY = "ARTIFACTORY_RELEASE_REPOSITORY" + + private static final String ARTIFACTORY_PROJECT_KEY = "ARTIFACTORY_PROJECT_KEY"; + + private static final String DEFAULT_ARTIFACTORY_URL = "https://repo.spring.io" + + private static final String DEFAULT_ARTIFACTORY_SNAPSHOT_REPOSITORY = "libs-snapshot-local" + + private static final String DEFAULT_ARTIFACTORY_MILESTONE_REPOSITORY = "libs-milestone-local" + + private static final String DEFAULT_ARTIFACTORY_RELEASE_REPOSITORY = "libs-release-local" + @Override void apply(Project project) { project.plugins.apply('com.jfrog.artifactory') String name = Utils.getProjectName(project); boolean isSnapshot = Utils.isSnapshot(project); boolean isMilestone = Utils.isMilestone(project); + Map env = System.getenv() + String artifactoryUrl = env.getOrDefault(ARTIFACTORY_URL_NAME, DEFAULT_ARTIFACTORY_URL) + String snapshotRepository = env.getOrDefault(ARTIFACTORY_SNAPSHOT_REPOSITORY, DEFAULT_ARTIFACTORY_SNAPSHOT_REPOSITORY) + String milestoneRepository = env.getOrDefault(ARTIFACTORY_MILESTONE_REPOSITORY, DEFAULT_ARTIFACTORY_MILESTONE_REPOSITORY) + String releaseRepository = env.getOrDefault(ARTIFACTORY_RELEASE_REPOSITORY, DEFAULT_ARTIFACTORY_RELEASE_REPOSITORY) + String projectKey = env.get(ARTIFACTORY_PROJECT_KEY) project.artifactory { - contextUrl = 'https://repo.spring.io' + contextUrl = artifactoryUrl publish { repository { - repoKey = isSnapshot ? 'libs-snapshot-local' : isMilestone ? 'libs-milestone-local' : 'libs-release-local' + repoKey = isSnapshot ? snapshotRepository : isMilestone ? milestoneRepository : releaseRepository if(project.hasProperty('artifactoryUsername')) { username = artifactoryUsername password = artifactoryPassword } } } + if (projectKey != null) { + clientConfig.info.setProject(projectKey) + } } project.plugins.withType(MavenPublishPlugin) { project.artifactory {