Skip to content

Java platform compatibility: remove auto apply on sub-projects #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ You can find instructions on how to apply the plugin at: http://plugins.gradle.
When applied on a project with sub-projects, the plugin will create the aggregation task `aggregateScoverage`, which
will first generate reports for each project individually (including the parent project), and will then generate an
aggregated result based on these reports.

The plugin must be applied on a sub-project for it to be included in the aggregated; applying the plugin on a
project _does not_ automatically apply it on sub-projects.

The aggregated report will override the parent-project specific report (`parent-project/build/reports/scoverage`).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Test;

public class MultiModulePluginNotConfiguredForScalaTest extends ScoverageFunctionalTest {

public MultiModulePluginNotConfiguredForScalaTest() {
super("multi-module-plugin-not-configured-for-scala");
}

@Test
public void checkAndAggregateScoverage() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME());

result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSkipped("scala_only:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSkipped(ScoveragePlugin.getCHECK_NAME());
result.assertTaskSkipped("scala_only:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSkipped(ScoveragePlugin.getAGGREGATE_NAME());

assertReportDirsEmpty();

Assert.assertTrue(result.getResult().getOutput().contains("Scala sub-project 'scala_only' doesn't have Scoverage applied"));
Assert.assertFalse(result.getResult().getOutput().contains("Scala sub-project 'java_only' doesn't have Scoverage applied"));
}

private void assertReportDirsEmpty() {

Assert.assertFalse(reportDir().exists());
Assert.assertFalse(reportDir(projectDir().toPath().resolve("scala_only").toFile()).exists());
Assert.assertFalse(reportDir(projectDir().toPath().resolve("java_only").toFile()).exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ public void checkAndAggregateScoverage() throws Exception {
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME());

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

result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getREPORT_NAME());

result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded("scala_only:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded("mixed_scala_java:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSkipped("java_only:" + ScoveragePlugin.getCHECK_NAME());

result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME());

assertAllReportFilesExist();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id 'org.scoverage' apply false
}

description = 'a multi-module Scala and Java project that defines scoverage only on root but not on subprojects'

allprojects {
repositories {
jcenter()
}
}

subprojects { p ->
if (p.name != 'dependencies') {
apply plugin: 'java'
dependencies {
implementation platform(project(':dependencies'))
testCompile group: 'org.junit.platform', name: 'junit-platform-runner'
}

test {
useJUnitPlatform()
}
}
}

apply plugin: 'org.scoverage'
scoverage {
minimumRate = 0.5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java-platform'
}

dependencies {
constraints {
api group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"

api group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
api group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion

api group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hello;

public class WorldJavaOnly {

public String foo() {
String s = "java_only" + "a";
return s;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.hello;

import org.junit.Test;

public class WorldJavaOnlyTest {

@Test
public void foo() {
new WorldJavaOnly().foo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apply plugin: 'scala'
// apply plugin: 'org.scoverage' // Oops forgot to configure scoverage

dependencies {
compile group: 'org.scala-lang', name: 'scala-library'

testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine'
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hello

class WorldScalaOnly {

def foo(): String = {
val s = "scala_only" + "a"
s
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class WorldScalaOnlySuite extends FunSuite {

test("foo") {
new WorldScalaOnly().foo()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include 'dependencies', 'java_only', 'scala_only'
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ plugins {
id 'org.scoverage' apply false
}

description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'

allprojects {
repositories {
jcenter()
}
}

description = 'a multi-module Scala and Java project that builds successfully with 100% coverage'

apply plugin: 'org.scoverage'

allprojects {
subprojects {
apply plugin: 'java'

dependencies {
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
Expand All @@ -21,12 +20,9 @@ allprojects {
test {
useJUnitPlatform()
}

scoverage {
minimumRate = 0.5
}
}

apply plugin: 'org.scoverage'
scoverage {
minimumRate = 0.5
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
apply plugin: 'java'

dependencies {

testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'org.scoverage'

dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
Expand All @@ -16,4 +14,9 @@ ext.configureSources = { set, name ->
set.java.srcDirs = []
}
configureSources(sourceSets.main, 'main')
configureSources(sourceSets.test, 'test')
configureSources(sourceSets.test, 'test')

apply plugin: 'org.scoverage'
scoverage {
minimumRate = 0.5
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'scala'
apply plugin: 'org.scoverage'

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

testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

apply plugin: 'org.scoverage'
scoverage {
minimumRate = 0.5
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.scoverage'
id 'org.scoverage' apply false
}

allprojects {
Expand All @@ -14,6 +14,7 @@ allprojects {

apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'org.scoverage'

dependencies {
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.scoverage'
id 'org.scoverage' apply false
}

allprojects {
Expand All @@ -14,6 +14,7 @@ allprojects {

apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'org.scoverage'

dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
plugins {
id 'org.scoverage'
id 'org.scoverage' apply false
}

allprojects {
description = 'a multi-module Scala project that builds successfully with 100% coverage'

allprojects { p ->
repositories {
jcenter()
}
}

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

allprojects {
dependencies {
implementation platform(project(':dependencies'))

apply plugin: 'java'
apply plugin: 'scala'
compile group: 'org.scala-lang', name: 'scala-library'

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

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

testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

test {
useJUnitPlatform()
}
test {
useJUnitPlatform()
}

scoverage {
minimumRate = 0.5
scoverage {
minimumRate = 0.5
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id 'java-platform'
}

dependencies {
constraints {
api group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"

api group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
api group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion

api group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include 'a', 'b', 'common'
include 'dependencies', 'a', 'b', 'common'
Loading