|
| 1 | +/* |
| 2 | + * Copyright 2017-present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | + * or implied. See the License for the specific language governing |
| 14 | + * permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.gradle.maven; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | + |
| 20 | +import org.gradle.api.Plugin; |
| 21 | +import org.gradle.api.Project; |
| 22 | +import org.gradle.api.publish.PublishingExtension; |
| 23 | +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; |
| 24 | + |
| 25 | +/** |
| 26 | + * Gradle Plugin used to publish all {@link Project} artifacts locally |
| 27 | + * under {@literal rootProject/buildDir/publications/repos}. |
| 28 | + * |
| 29 | + * This is useful for inspecting the generated {@link Project} artifacts to ensure they are correct |
| 30 | + * before publishing the {@link Project} artifacts to Artifactory or Maven Central. |
| 31 | + * |
| 32 | + * @author Rob Winch |
| 33 | + * @author John Blum |
| 34 | + * @see org.gradle.api.Plugin |
| 35 | + * @see org.gradle.api.Project |
| 36 | + * @since 2.0.0 |
| 37 | + */ |
| 38 | +public class PublishLocalPlugin implements Plugin<Project> { |
| 39 | + |
| 40 | + @Override |
| 41 | + public void apply(Project project) { |
| 42 | + |
| 43 | + project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> { |
| 44 | + |
| 45 | + PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); |
| 46 | + |
| 47 | + publishing.getRepositories().maven(maven -> { |
| 48 | + maven.setName("local"); |
| 49 | + maven.setUrl(new File(project.getRootProject().getBuildDir(), "publications/repos")); |
| 50 | + }); |
| 51 | + }); |
| 52 | + } |
| 53 | +} |
0 commit comments