Add artifactory publish
- This adds needed plugin configurations to gradle buildSrc enabling publish and configures credentials via artifactoryUsername and artifactoryPassword. - Artifactory context url defaults to https://repo.spring.io but can be customised via artifactoryContextUrl. - Relates #165
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id "base"
|
||||
id 'org.springframework.security.kerberos.root'
|
||||
}
|
||||
|
||||
description = 'Spring Security Kerberos'
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.gradle.api.publish.tasks.GenerateModuleMetadata;
|
||||
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpec;
|
||||
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpecs;
|
||||
import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin;
|
||||
import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention;
|
||||
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,28 @@ public class ArtifactoryConventions {
|
||||
});
|
||||
|
||||
project.getPlugins().withType(ArtifactoryPlugin.class, artifactory -> {
|
||||
if (isRootProject(project)) {
|
||||
ArtifactoryPluginConvention apConvention = (ArtifactoryPluginConvention) project.getConvention()
|
||||
.getPlugins().get("artifactory");
|
||||
if (project.hasProperty("artifactoryContextUrl")) {
|
||||
apConvention.setContextUrl(project.property("artifactoryContextUrl"));
|
||||
}
|
||||
else {
|
||||
apConvention.setContextUrl("https://repo.spring.io");
|
||||
}
|
||||
apConvention.publish(publisherConfig -> {
|
||||
publisherConfig.invokeMethod("setPublishBuildInfo", new Object[] { false });
|
||||
publisherConfig.repository(repository -> {
|
||||
String repoKey = Utils.isSnapshot(project) ? "libs-snapshot-local"
|
||||
: Utils.isMilestone(project) ? "libs-milestone-local" : "libs-release-local";
|
||||
repository.setRepoKey(repoKey);
|
||||
if (project.hasProperty("artifactoryUsername") && project.hasProperty("artifactoryPassword") ) {
|
||||
repository.setUsername(project.property("artifactoryUsername"));
|
||||
repository.setPassword(project.property("artifactoryPassword"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Task task = project.getTasks().findByName(ArtifactoryTask.ARTIFACTORY_PUBLISH_TASK_NAME);
|
||||
if (task != null) {
|
||||
ArtifactoryTask aTask = (ArtifactoryTask) task;
|
||||
@@ -48,7 +71,8 @@ public class ArtifactoryConventions {
|
||||
// bom is not a java project so plugin doesn't
|
||||
// add defaults for publications.
|
||||
aTask.publications("mavenJava");
|
||||
aTask.publishConfigs("archives");
|
||||
// aTask.publishConfigs("archives");
|
||||
aTask.setPublishIvy(false);
|
||||
|
||||
// plugin is difficult to work with, use this hack
|
||||
// to set props before task does its real work
|
||||
@@ -71,4 +95,8 @@ public class ArtifactoryConventions {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isRootProject(Project project) {
|
||||
return project.equals(project.getRootProject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2023 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 the License at
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class Utils {
|
||||
|
||||
static boolean isSnapshot(Project project) {
|
||||
String projectVersion = projectVersion(project);
|
||||
return projectVersion.matches("^.*([.-]BUILD)?-SNAPSHOT$");
|
||||
}
|
||||
|
||||
static boolean isMilestone(Project project) {
|
||||
String projectVersion = projectVersion(project);
|
||||
return projectVersion.matches("^.*[.-]M\\d+$") || projectVersion.matches("^.*[.-]RC\\d+$");
|
||||
}
|
||||
|
||||
static boolean isRelease(Project project) {
|
||||
return !(isSnapshot(project) || isMilestone(project));
|
||||
}
|
||||
|
||||
private static String projectVersion(Project project) {
|
||||
return String.valueOf(project.getVersion());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user