| 1 |
/* |
| 2 |
* Copyright 2002-2014 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 org.springframework.build.gradle.propdep |
| 18 |
|
| 19 |
import org.gradle.api.* |
| 20 |
import org.gradle.api.artifacts.Configuration |
| 21 |
import org.gradle.api.artifacts.ConfigurationContainer |
| 22 |
import org.gradle.api.plugins.JavaPlugin |
| 23 |
import org.gradle.api.tasks.javadoc.Javadoc |
| 24 |
|
| 25 |
/** |
| 26 |
* Plugin to allow 'optional' and 'provided' dependency configurations |
| 27 |
* |
| 28 |
* As stated in the maven documentation, provided scope "is only available on the compilation and test classpath, |
| 29 |
* and is not transitive". |
| 30 |
* |
| 31 |
* This plugin creates two new configurations, and each one: |
| 32 |
* <ul> |
| 33 |
* <li>is a parent of the compile configuration</li> |
| 34 |
* <li>is not visible, not transitive</li> |
| 35 |
* <li>all dependencies are excluded from the default configuration</li> |
| 36 |
* </ul> |
| 37 |
* |
| 38 |
* @author Phillip Webb |
| 39 |
* @author Brian Clozel |
| 40 |
* |
| 41 |
* @see <a href="http://www.gradle.org/docs/current/userguide/java_plugin.html#N121CF">Maven documentation</a> |
| 42 |
* @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">Gradle configurations</a> |
| 43 |
* @see PropDepsEclipsePlugin |
| 44 |
* @see PropDepsIdeaPlugin |
| 45 |
* @see PropDepsMavenPlugin |
| 46 |
*/ |
| 47 |
class PropDepsPlugin implements Plugin<Project> { |
| 48 |
|
| 49 |
public void apply(Project project) { |
| 50 |
project.plugins.apply(JavaPlugin) |
| 51 |
|
| 52 |
Configuration provided = addConfiguration(project.configurations, "provided") |
| 53 |
Configuration optional = addConfiguration(project.configurations, "optional") |
| 54 |
|
| 55 |
Javadoc javadoc = project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME) |
| 56 |
javadoc.classpath = javadoc.classpath.plus(provided).plus(optional) |
| 57 |
} |
| 58 |
|
| 59 |
private Configuration addConfiguration(ConfigurationContainer configurations, String name) { |
| 60 |
Configuration compile = configurations.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME) |
| 61 |
Configuration configuration = configurations.create(name) |
| 62 |
|
| 63 |
compile.extendsFrom(configuration) |
| 64 |
configuration.visible = false |
| 65 |
configuration.transitive = false |
| 66 |
|
| 67 |
configuration.allDependencies.all { |
| 68 |
dep -> configurations.default.exclude(group: dep.group, module: dep.name) |
| 69 |
} |
| 70 |
|
| 71 |
return configuration |
| 72 |
} |
| 73 |
|
| 74 |
} |