Skip to content

Commit 328a931

Browse files
committed
Use local Spring PropDepsPlugin Gradle Pugins.
1 parent 2ae4314 commit 328a931

File tree

5 files changed

+254
-1
lines changed

5 files changed

+254
-1
lines changed

buildSrc/build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ repositories {
1919
maven { url 'https://repo.spring.io/plugins-release/' }
2020
}
2121

22+
gradlePlugin {
23+
plugins {
24+
managementConfiguration {
25+
id = "io.spring.convention.management-configuration"
26+
implementationClass = "io.spring.gradle.convention.ManagementConfigurationPlugin"
27+
}
28+
propdeps {
29+
id = "org.springframework.propdeps"
30+
implementationClass = "org.springframework.gradle.propdeps.PropDepsPlugin"
31+
}
32+
}
33+
}
34+
2235
configurations {
2336
implementation {
2437
exclude module: 'groovy-all'
@@ -33,7 +46,6 @@ dependencies {
3346
implementation 'gradle.plugin.org.gretty:gretty:3.0.1'
3447
implementation 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.1'
3548
implementation 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
36-
implementation 'io.spring.gradle:propdeps-plugin:0.0.10.RELEASE'
3749
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.15'
3850
implementation 'io.spring.nohttp:nohttp-gradle:0.0.3.RELEASE'
3951
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.1.0'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 io.spring.gradle.propdeps
17+
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
import org.gradle.plugins.ide.eclipse.EclipsePlugin
21+
22+
/**
23+
* Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations
24+
* to work with the standard Gradle {@link EclipsePlugin}.
25+
*
26+
* @author Phillip Webb
27+
* @author John Blum
28+
* @see org.gradle.api.Plugin
29+
* @see org.gradle.api.Project
30+
* @see org.gradle.plugins.ide.eclipse.EclipsePlugin
31+
*/
32+
class PropDepsEclipsePlugin implements Plugin<Project> {
33+
34+
void apply(Project project) {
35+
36+
project.plugins.apply(PropDepsPlugin)
37+
project.plugins.apply(EclipsePlugin)
38+
39+
project.eclipse {
40+
classpath {
41+
plusConfigurations += [ project.configurations.provided, project.configurations.optional ]
42+
}
43+
}
44+
}
45+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 io.spring.gradle.propdeps
17+
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
import org.gradle.plugins.ide.idea.IdeaPlugin
21+
22+
/**
23+
* Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations
24+
* to work with the standard Gradle {@link IdeaPlugin}.
25+
*
26+
* @author Phillip Webb
27+
* @author Brian Clozel
28+
* @author John Blum
29+
* @see org.gradle.api.Plugin
30+
* @see org.gradle.api.Project
31+
* @see org.gradle.plugins.ide.idea.IdeaPlugin
32+
* @link https://youtrack.jetbrains.com/issue/IDEA-107046
33+
* @link https://youtrack.jetbrains.com/issue/IDEA-117668
34+
*/
35+
class PropDepsIdeaPlugin implements Plugin<Project> {
36+
37+
void apply(Project project) {
38+
39+
project.plugins.apply(PropDepsPlugin)
40+
project.plugins.apply(IdeaPlugin)
41+
project.idea.module {
42+
// IntelliJ IDEA internally deals with 4 scopes : COMPILE, TEST, PROVIDED, RUNTIME
43+
// but only PROVIDED seems to be picked up
44+
scopes.PROVIDED.plus += [ project.configurations.provided ]
45+
scopes.PROVIDED.plus += [ project.configurations.optional ]
46+
}
47+
}
48+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2002-2012 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+
* http://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 or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.gradle.propdeps
18+
19+
import org.gradle.api.*
20+
import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer
21+
import org.gradle.api.artifacts.maven.MavenPom
22+
import org.gradle.api.artifacts.maven.PomFilterContainer
23+
import org.gradle.api.plugins.MavenPlugin
24+
import org.gradle.api.tasks.*
25+
26+
27+
/**
28+
* Plugin to allow optional and provided dependency configurations to work with the
29+
* standard gradle 'maven' plugin
30+
*
31+
* @author Phillip Webb
32+
*/
33+
class PropDepsMavenPlugin implements Plugin<Project> {
34+
35+
public void apply(Project project) {
36+
project.plugins.apply(PropDepsPlugin)
37+
project.plugins.apply(MavenPlugin)
38+
39+
Conf2ScopeMappingContainer scopeMappings = project.conf2ScopeMappings
40+
scopeMappings.addMapping(MavenPlugin.COMPILE_PRIORITY + 1,
41+
project.configurations.getByName("provided"), Conf2ScopeMappingContainer.PROVIDED)
42+
43+
// Add a temporary new optional scope
44+
scopeMappings.addMapping(MavenPlugin.COMPILE_PRIORITY + 2,
45+
project.configurations.getByName("optional"), "optional")
46+
47+
// Add a hook to replace the optional scope
48+
project.afterEvaluate {
49+
project.tasks.withType(Upload).each { applyToUploadTask(project, it) }
50+
}
51+
}
52+
53+
private void applyToUploadTask(Project project, Upload upload) {
54+
upload.repositories.withType(PomFilterContainer).each{ applyToPom(project, it) }
55+
}
56+
57+
private void applyToPom(Project project, PomFilterContainer pomContainer) {
58+
pomContainer.pom.whenConfigured { MavenPom pom ->
59+
pom.dependencies.findAll{ it.scope == "optional" }.each {
60+
it.scope = "compile"
61+
it.optional = true
62+
}
63+
}
64+
}
65+
66+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 io.spring.gradle.propdeps
17+
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
import org.gradle.api.artifacts.Configuration
21+
import org.gradle.api.plugins.JavaLibraryPlugin
22+
import org.gradle.api.plugins.JavaPlugin
23+
import org.gradle.api.tasks.javadoc.Javadoc
24+
25+
/**
26+
* Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations.
27+
*
28+
* As stated in the Maven documentation, {@literal provided} scope {@literal "is only available on the compilation
29+
* and test classpath, and is not transitive"}.
30+
*
31+
* This {@link Plugin} creates two new configurations, and each one:
32+
*
33+
* <ul>
34+
* <li>is a parent of the compile configuration</li>
35+
* <li>is not visible, not transitive</li>
36+
* <li>all dependencies are excluded from the default configuration</li>
37+
* </ul>
38+
*
39+
* @author Phillip Webb
40+
* @author Brian Clozel
41+
* @author Rob Winch
42+
* @author John Blum
43+
*
44+
* @see org.gradle.api.Plugin
45+
* @see org.gradle.api.Project
46+
* @see PropDepsEclipsePlugin
47+
* @see PropDepsIdeaPlugin
48+
* @see <a href="https://www.gradle.org/docs/current/userguide/java_plugin.html#N121CF">Maven documentation</a>
49+
* @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">Gradle configurations</a>
50+
*/
51+
class PropDepsPlugin implements Plugin<Project> {
52+
53+
void apply(Project project) {
54+
55+
project.plugins.apply(JavaPlugin)
56+
57+
Configuration optional = addConfiguration(project, "optional")
58+
Configuration provided = addConfiguration(project, "provided")
59+
60+
Javadoc javadoc = project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME)
61+
62+
javadoc.classpath = javadoc.classpath + provided + optional
63+
}
64+
65+
private Configuration addConfiguration(Project project, String name) {
66+
67+
Configuration configuration = project.configurations.create(name)
68+
69+
configuration.extendsFrom(project.configurations.implementation)
70+
71+
project.plugins.withType(JavaLibraryPlugin, {
72+
configuration.extendsFrom(project.configurations.api)
73+
})
74+
75+
project.sourceSets.all {
76+
compileClasspath += configuration
77+
runtimeClasspath += configuration
78+
}
79+
80+
return configuration
81+
}
82+
}

0 commit comments

Comments
 (0)