Skip to content

Commit 11d5027

Browse files
committed
(#121) Make the plugin compatible with java-platform plugin by removing auto-apply on subprojects
1 parent d5e4c9b commit 11d5027

File tree

11 files changed

+83
-68
lines changed

11 files changed

+83
-68
lines changed

src/functionalTest/java/org.scoverage/ScalaJavaMultiModuleTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ public void checkAndAggregateScoverage() throws Exception {
1818
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
1919
ScoveragePlugin.getAGGREGATE_NAME());
2020

21-
result.assertTaskOutcome("java_only:" + ScoveragePlugin.getCOMPILE_NAME(), TaskOutcome.NO_SOURCE);
21+
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCOMPILE_NAME());
2222

2323
result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
2424
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getREPORT_NAME());
2525
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getREPORT_NAME());
2626
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME());
27+
2728
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
2829
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getCHECK_NAME());
2930
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getCHECK_NAME());
3031
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME());
32+
3133
result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME());
3234

3335
assertAllReportFilesExist();

src/functionalTest/resources/projects/scala-java-multi-module/build.gradle

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ plugins {
22
id 'org.scoverage' apply false
33
}
44

5+
description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'
6+
57
allprojects {
68
repositories {
79
jcenter()
810
}
911
}
1012

11-
description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'
12-
13-
apply plugin: 'org.scoverage'
14-
15-
allprojects {
13+
subprojects {
14+
apply plugin: 'java'
1615

1716
dependencies {
1817
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
@@ -21,12 +20,9 @@ allprojects {
2120
test {
2221
useJUnitPlatform()
2322
}
24-
25-
scoverage {
26-
minimumRate = 0.5
27-
}
2823
}
2924

25+
apply plugin: 'org.scoverage'
3026
scoverage {
3127
minimumRate = 0.5
3228
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
apply plugin: 'java'
2-
31
dependencies {
4-
52
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
63
}

src/functionalTest/resources/projects/scala-java-multi-module/mixed_scala_java/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
apply plugin: 'java'
21
apply plugin: 'scala'
3-
apply plugin: 'org.scoverage'
42

53
dependencies {
64
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
@@ -16,4 +14,9 @@ ext.configureSources = { set, name ->
1614
set.java.srcDirs = []
1715
}
1816
configureSources(sourceSets.main, 'main')
19-
configureSources(sourceSets.test, 'test')
17+
configureSources(sourceSets.test, 'test')
18+
19+
apply plugin: 'org.scoverage'
20+
scoverage {
21+
minimumRate = 0.5
22+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'scala'
2-
apply plugin: 'org.scoverage'
32

43
dependencies {
54
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
@@ -8,3 +7,8 @@ dependencies {
87

98
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
109
}
10+
11+
apply plugin: 'org.scoverage'
12+
scoverage {
13+
minimumRate = 0.5
14+
}

src/functionalTest/resources/projects/scala-multi-module-cross-version/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

55
allprojects {
@@ -14,6 +14,7 @@ allprojects {
1414

1515
apply plugin: 'java'
1616
apply plugin: 'scala'
17+
apply plugin: 'org.scoverage'
1718

1819
dependencies {
1920
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion

src/functionalTest/resources/projects/scala-multi-module-multiple-test-tasks/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

55
allprojects {
@@ -14,6 +14,7 @@ allprojects {
1414

1515
apply plugin: 'java'
1616
apply plugin: 'scala'
17+
apply plugin: 'org.scoverage'
1718

1819
dependencies {
1920
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
plugins {
2-
id 'org.scoverage'
2+
id 'org.scoverage' apply false
33
}
44

5-
allprojects {
5+
description = 'a multi-module Scala project that builds successfully with 100% coverage'
6+
7+
allprojects { p ->
68
repositories {
79
jcenter()
810
}
9-
}
1011

11-
description = 'a multi-module Scala project that builds successfully with 100% coverage'
12+
if (p.name != 'dependencies') {
13+
apply plugin: 'java'
14+
apply plugin: 'scala'
15+
apply plugin: 'org.scoverage'
1216

13-
allprojects {
17+
dependencies {
18+
implementation platform(project(':dependencies'))
1419

15-
apply plugin: 'java'
16-
apply plugin: 'scala'
20+
compile group: 'org.scala-lang', name: 'scala-library'
1721

18-
dependencies {
19-
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
22+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
23+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner'
2024

21-
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
22-
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
25+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}"
26+
}
2327

24-
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
25-
}
26-
27-
test {
28-
useJUnitPlatform()
29-
}
28+
test {
29+
useJUnitPlatform()
30+
}
3031

31-
scoverage {
32-
minimumRate = 0.5
32+
scoverage {
33+
minimumRate = 0.5
34+
}
3335
}
3436
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'java-platform'
3+
}
4+
5+
dependencies {
6+
constraints {
7+
api group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
8+
9+
api group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
10+
api group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
11+
12+
api group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
13+
}
14+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include 'a', 'b', 'common'
1+
include 'dependencies', 'a', 'b', 'common'

src/main/groovy/org/scoverage/ScoveragePlugin.groovy

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class ScoveragePlugin implements Plugin<PluginAware> {
3232
void apply(PluginAware pluginAware) {
3333
if (pluginAware instanceof Project) {
3434
applyProject(pluginAware)
35-
if (pluginAware == pluginAware.rootProject) {
36-
pluginAware.subprojects { p ->
37-
p.plugins.apply(ScoveragePlugin)
38-
}
39-
}
4035
} else if (pluginAware instanceof Gradle) {
4136
pluginAware.allprojects { p ->
4237
p.plugins.apply(ScoveragePlugin)
@@ -104,7 +99,6 @@ class ScoveragePlugin implements Plugin<PluginAware> {
10499
def globalReportTask = project.tasks.register(REPORT_NAME, ScoverageAggregate)
105100
def globalCheckTask = project.tasks.register(CHECK_NAME, OverallCheckTask)
106101

107-
108102
project.afterEvaluate {
109103
def detectedSourceEncoding = compileTask.scalaCompileOptions.encoding
110104
if (detectedSourceEncoding == null) {
@@ -166,29 +160,6 @@ class ScoveragePlugin implements Plugin<PluginAware> {
166160
reportDir = extension.reportDir
167161
}
168162

169-
// define aggregation task
170-
if (project.childProjects.size() > 0) {
171-
def allReportTasks = project.getAllprojects().findResults {
172-
it.tasks.find { task ->
173-
task.name == REPORT_NAME && task instanceof ScoverageAggregate
174-
}
175-
}
176-
177-
def aggregationTask = project.tasks.create(AGGREGATE_NAME, ScoverageAggregate) {
178-
dependsOn(allReportTasks)
179-
group = 'verification'
180-
runner = scoverageRunner
181-
reportDir = extension.reportDir
182-
sourceEncoding.set(detectedSourceEncoding)
183-
deleteReportsOnAggregation = extension.deleteReportsOnAggregation
184-
coverageOutputCobertura = extension.coverageOutputCobertura
185-
coverageOutputXML = extension.coverageOutputXML
186-
coverageOutputHTML = extension.coverageOutputHTML
187-
coverageDebug = extension.coverageDebug
188-
}
189-
project.tasks[CHECK_NAME].mustRunAfter(aggregationTask)
190-
}
191-
192163
// make this project's scoverage compilation depend on scoverage compilation of any other project
193164
// which this project depends on its normal compilation
194165
// (essential when running without normal compilation on multi-module projects with inner dependencies)
@@ -308,6 +279,30 @@ class ScoveragePlugin implements Plugin<PluginAware> {
308279
}
309280
}
310281
}
282+
283+
// define aggregation task
284+
if (project.childProjects.size() > 0) {
285+
project.gradle.projectsEvaluated {
286+
def allReportTasks = project.getAllprojects().findResults {
287+
it.tasks.find { task ->
288+
task.name == REPORT_NAME && task instanceof ScoverageAggregate
289+
}
290+
}
291+
def aggregationTask = project.tasks.create(AGGREGATE_NAME, ScoverageAggregate) {
292+
dependsOn(allReportTasks)
293+
group = 'verification'
294+
runner = scoverageRunner
295+
reportDir = extension.reportDir
296+
sourceEncoding.set(detectedSourceEncoding)
297+
deleteReportsOnAggregation = extension.deleteReportsOnAggregation
298+
coverageOutputCobertura = extension.coverageOutputCobertura
299+
coverageOutputXML = extension.coverageOutputXML
300+
coverageOutputHTML = extension.coverageOutputHTML
301+
coverageDebug = extension.coverageDebug
302+
}
303+
project.tasks[CHECK_NAME].mustRunAfter(aggregationTask)
304+
}
305+
}
311306
}
312307
}
313308

0 commit comments

Comments
 (0)