scoverage / gradle-scoverage

A plugin to enable the use of Scoverage in a gradle Scala project
Apache License 2.0
53 stars 38 forks source link

Task 'aggregateScoverage' not found in root project #176

Open mwos-sl opened 3 years ago

mwos-sl commented 3 years ago

I've got multi-project gradle build. Root build.gradle:

plugins {
  ...
  id "org.scoverage" version "7.0.0" apply false
}

allprojects  {
  ...

  apply plugin: "scala"
  apply plugin: 'java-library'
  // NOTE applying also for root project
  apply plugin: "org.scoverage"

  dependencies {
    api("org.scala-lang:scala-library:$scalaMajorVersion.$scalaMinorVersion")
  }

  scoverage {
    scoverageVersion = "1.4.10"
  }
}

When I call

./gradlew dummy:reportScoverage util:reportScoverage aggregateScoverage

I get error:

Task 'aggregateScoverage' not found in root project 'all'.

So even though it seems it should be there (https://github.com/scoverage/gradle-scoverage/blob/master/src/main/groovy/org/scoverage/ScoveragePlugin.groovy#L313), I followed the answers from some other issues (https://github.com/scoverage/gradle-scoverage/issues/33, https://github.com/scoverage/gradle-scoverage/issues/85#issuecomment-450426947, https://github.com/scoverage/gradle-scoverage/issues/66) and added this in the root:

task aggregateScoverage(type: org.scoverage.ScoverageAggregate)

without even defining dependancy yet, and when I rerun the gradlew command I get:

Cannot add task 'aggregateScoverage' as a task with that name already exists.

even though it was claimed to not exist before I added 🤯

Env

scala 2.11.15 gradle 7.2 gradle scoverage plugin 7.0.0 scoverage 1.4.10

mwos-sl commented 2 years ago

Hmm, but the code seem strange, because inside project.afterEvaluate: https://github.com/scoverage/gradle-scoverage/blame/master/src/main/groovy/org/scoverage/ScoveragePlugin.groovy#L106

we say project.gradle.projectsEvaluated: https://github.com/scoverage/gradle-scoverage/blame/master/src/main/groovy/org/scoverage/ScoveragePlugin.groovy#L297

and inside this one aggregateScoverage is declared: https://github.com/scoverage/gradle-scoverage/blame/master/src/main/groovy/org/scoverage/ScoveragePlugin.groovy#L313

But gradle has no chances to jump into this block, because somewhere between those 2 gradle checks gradle checks if the task which we're calling from the console (aggregateScoverage) exists. And of course it does not yet, so gradle fails as described:

Task 'aggregateScoverage' not found in root project 'all'.

As a result we never go into the clousure defined within project.gradle.projectsEvaluated.

Question: Why project.gradle.projectsEvaluated is needed (https://github.com/scoverage/gradle-scoverage/blame/master/src/main/groovy/org/scoverage/ScoveragePlugin.groovy#L297) in the first place? Isn't the fact that this is inside afterEvaluate enough?

cc @eyalroth I see you were the last one touching this area, so maybe you know?

mwos-sl commented 2 years ago

Huh, configuration-on-demand changes behaviour of project.gradle.projectsEvaluated.

When I temporarily disabled it:

org.gradle.configureondemand=false

then it enters the scope which creates aggregateScoverage.

I think this very old issue is related: https://github.com/gradle/gradle/issues/9489 and it doesn't seem it's going to be addressed.

Unfortunately disabling configuration-on-demand isn't a proper fix for us, as we need configuration-on-demand (we've got monorepo with severa hundreds of modules).

q-benwillis commented 1 year ago

@mwos-sl Did you ever find a solution to this? Currently seeing the same issue when attempting to use the plugin with configuration-on-demand enabled in a mono-repo with a large number of projects.

wosiu commented 1 year ago

From what I remember we eventually picked a different plugin for this.

On Wed, Jun 28, 2023, 17:27 Ben Willis @.***> wrote:

@mwos-sl https://github.com/mwos-sl Did you ever find a solution to this? Currently seeing the same issue when attempting to use the plugin with configuration-on-demand enabled in a mono-repo with a large number of projects.

— Reply to this email directly, view it on GitHub https://github.com/scoverage/gradle-scoverage/issues/176#issuecomment-1611649270, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF4AJETCYOJAZ52UQNQUYLXNRENVANCNFSM5INALM5A . You are receiving this because you are subscribed to this thread.Message ID: @.***>