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 1 commit
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
Prev Previous commit
Next Next commit
(#121) Add a warning when scala subprojects don't have scoverage appl…
…ied to them (and the parent does)
  • Loading branch information
eyalroth committed Oct 28, 2019
commit 7547f04879b75d2f273e9a968df74da712d6c636
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
@@ -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'
14 changes: 12 additions & 2 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.invocation.Gradle
import org.gradle.api.plugins.PluginAware
import org.gradle.api.plugins.scala.ScalaPlugin
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.scala.ScalaCompile
import org.gradle.api.tasks.testing.Test
Expand Down Expand Up @@ -281,14 +282,23 @@ class ScoveragePlugin implements Plugin<PluginAware> {
}

// define aggregation task
if (project.childProjects.size() > 0) {
if (!project.subprojects.empty) {
project.gradle.projectsEvaluated {
def allReportTasks = project.getAllprojects().findResults {
project.subprojects.each {
if (it.plugins.hasPlugin(ScalaPlugin) && !it.plugins.hasPlugin(ScoveragePlugin)) {
it.logger.warn("Scala sub-project '${it.name}' doesn't have Scoverage applied and will be ignored in parent project aggregation")
}
}
def childReportTasks = project.subprojects.findResults {
it.tasks.find { task ->
task.name == REPORT_NAME && task instanceof ScoverageAggregate
}
}
def allReportTasks = childReportTasks + globalReportTask
def aggregationTask = project.tasks.create(AGGREGATE_NAME, ScoverageAggregate) {
onlyIf {
!childReportTasks.empty
}
dependsOn(allReportTasks)
group = 'verification'
runner = scoverageRunner
Expand Down