-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyzeDependenciesPlugin.groovy
76 lines (69 loc) · 3.02 KB
/
AnalyzeDependenciesPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ca.cutterslade.gradle.analyze
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import java.util.concurrent.ConcurrentHashMap
class AnalyzeDependenciesPlugin implements Plugin<Project> {
@Override
void apply(final Project project) {
if (project.rootProject == project) {
project.rootProject.extensions.add(ProjectDependencyResolver.CACHE_NAME, new ConcurrentHashMap<>())
}
project.plugins.withId('java') {
project.configurations.create('permitUnusedDeclared')
project.configurations.create('permitTestUnusedDeclared')
project.configurations.create('permitUsedUndeclared')
project.configurations.create('permitTestUsedUndeclared')
def mainTask = project.task('analyzeClassesDependencies',
dependsOn: ['classes', project.configurations.compile],
type: AnalyzeDependenciesTask,
group: 'Verification',
description: 'Analyze project for dependency issues related to main source set.'
) {
require = [
project.configurations.compile,
project.configurations.findByName('compileOnly'),
project.configurations.findByName('provided'),
project.configurations.findByName('compileClasspath')
]
allowedToUse = [
project.configurations.permitUsedUndeclared
]
allowedToDeclare = [
project.configurations.permitUnusedDeclared
]
def output = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).output
classesDirs = output.hasProperty('classesDirs') ? output.classesDirs : project.files(output.classesDir)
}
def testTask = project.task('analyzeTestClassesDependencies',
dependsOn: ['testClasses', project.configurations.testCompile],
type: AnalyzeDependenciesTask,
group: 'Verification',
description: 'Analyze project for dependency issues related to test source set.'
) {
require = [
project.configurations.testCompile,
project.configurations.findByName('testCompileOnly'),
project.configurations.findByName('testCompileClasspath')
]
allowedToUse = [
project.configurations.compile,
project.configurations.permitTestUsedUndeclared,
project.configurations.findByName('provided'),
project.configurations.findByName('compileClasspath'),
project.configurations.findByName('runtimeClasspath')
]
allowedToDeclare = [
project.configurations.permitTestUnusedDeclared
]
def output = project.sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).output
classesDirs = output.hasProperty('classesDirs') ? output.classesDirs : project.files(output.classesDir)
}
project.check.dependsOn project.task('analyzeDependencies',
dependsOn: [mainTask, testTask],
group: 'Verification',
description: 'Analyze project for dependency issues.'
)
}
}
}