Skip to content
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

Gradle task with Jacoco code coverage fails after upgrade to Gradle 7 #16860

Open
jan-dolejsi opened this issue Sep 8, 2022 · 21 comments
Open
Assignees
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug Task: Gradle

Comments

@jan-dolejsi
Copy link

Bug
Type: build task fails

Enter Task Name: Gradle,v2

Environment

  • Azure Pipelines

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number:

Gradle+Jacoco:
https://dev.azure.com/slb-swt/ai-planning/_build/results?buildId=4043438&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=ea098990-53e4-52aa-5a84-5ead7c5f17f2&l=167

  • Agent - Hosted or Private:

    • If using Hosted agent, provide agent queue name: hosted

Issue Description

Yaml pipeline:

pool:
  vmImage: 'ubuntu-latest'

steps:
  - task: Gradle@2
    inputs:
      gradleWrapperFile: 'gradlew'
      tasks: 'build'
      publishJUnitResults: true
      testResultsFiles: '**/TEST-*.xml'
      codeCoverageToolOption: 'JaCoCo'
      codeCoverageClassFilesDirectories: 'build/classes/java/main/'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.11'
      gradleOptions: '-Xmx3072m'
      sonarQubeRunAnalysis: false
      spotBugsAnalysis: false

Gradle.properties

gradleVersion=7.4.2

Gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Task logs

> Task :processTestResources
> Task :testClasses
> Task :test
> Task :jacocoTestReport FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/home/vsts/work/1/s/build.gradle' line: 70

* What went wrong:
Execution failed for task ':jacocoTestReport'.
@github-actions github-actions bot added Area: ABTT Akvelon Build Tasks Team area of work Task: Gradle triage labels Sep 8, 2022
@vmapetr
Copy link
Contributor

vmapetr commented Sep 9, 2022

Hi @jan-dolejsi
Thank you for your report,
We are working on more prioritized issues at the moment but will get back to this one soon.

@vmapetr vmapetr added bug and removed triage labels Sep 9, 2022
@idrisscharai
Copy link

Any updates on this issue please?

@github-actions
Copy link

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot added the stale label Apr 15, 2023
@kaito-ms
Copy link

Any updates on this issue please?

This problem is caused by the Gradle task writing the following to the build.gradle file

// build.gradle
classDirectories.setFrom fileTree(dir: "build/classes/java/main/").exclude(jacocoExcludes).include(jacocoIncludes)

In Gradle 6.x and later, classDirectories is read-only.
JacocoReport - Gradle DSL Version 7.6.1

In Gradle 5.x, it was possible to write values to classDirectories, so the problem did not occur.
JacocoReport - Gradle DSL Version 5.6.4

@github-actions github-actions bot removed the stale label Apr 18, 2023
@sreich
Copy link

sreich commented May 3, 2023

I am also interested in an update on this. Nice investigation/root cause analysis @kaito-ms

@mikeviggiani
Copy link

Thanks @kaito-ms and @jan-dolejsi for highlighting this issue.

I am also running into this and interested in a resolution!

@vmapetr vmapetr self-assigned this Jul 19, 2023
@morrowyn
Copy link

morrowyn commented Aug 4, 2023

I have the same problem. I'm getting the following error: The value for this file collection is final and cannot be changed.

@mikeviggiani
Copy link

You can add it to build.gradle following Gradles plugin documentation as a workaround.

@morrowyn
Copy link

morrowyn commented Aug 4, 2023

I have added the following to my build.gradle

jacocoTestReport {
	classDirectories.setFrom fileTree(dir: "build/classes/java/main/").exclude('').include('')
}

and I still receive the same error. I'm using gradle 7.6.1 by the way.

If I used

jacocoTestReport {
	classDirectories.setFrom fileTree(dir: "build/classes/java/main/").exclude(jacocoExcludes).include(jacocoIncludes)
}

I get the following error:

What went wrong:
A problem occurred evaluating root project 'notifications'.
> Could not get unknown property 'jacocoExcludes' for task ':jacocoTestReport' of type org.gradle.testing.jacoco.tasks.JacocoReport.

@mikeviggiani
Copy link

I used the following. Agent running Gradle 8.0

plugins {
id 'jacoco'
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = true
}
}

@morrowyn
Copy link

morrowyn commented Aug 4, 2023

Still the same error with 7.6.1
With 8.2.1 I get :

Could not set unknown property 'enabled' for Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport.

@matthewcorven
Copy link

Still the same error with 7.6.1 With 8.2.1 I get :

Could not set unknown property 'enabled' for Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport.

I have the same issue with Gradle 8.0.2 and 8.4.

@vicky17d
Copy link

Hi
Any updates on this? Any workaround?
It was working fine in 6.9.4 (even though the documentation says readOnly for classDirectories)

After upgrading to Gradle 7, it is failing

@max-zaytsev max-zaytsev assigned max-zaytsev and unassigned vmapetr Oct 23, 2023
@rs10615
Copy link

rs10615 commented Nov 17, 2023

Any Update on this issue , I am upgrading my from 6.8 to 7 and getting the following error . They are 6 vulnerabilities reported by the sonar for gradle v6.x

Could not set unknown property 'enabled' for Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport.

@NickJohn98
Copy link

I'm facing this when upgrading to gradle 8.3. Any update?

@olegpoltora
Copy link

Gradle - 8.4
jacoco toolVersion - 0.8.9

At local environment all is ok.
Problem ONLY at azure:

/home/vsts/work/1/s/gradlew clean build jacocoTestReport

> Configure project :
0.8.9

FAILURE: Build failed with an exception.

* Where:
Build file '/home/vsts/work/1/s/build.gradle' line: 105

* What went wrong:
A problem occurred evaluating root project 'lead-time-prediction-history'.
> Could not set unknown property 'enabled' for Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport.

build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'io.freefair.lombok' version '8.0.1'
    id 'jacoco'
}

// java, repositories, dependencies and other blocks are skipped...

test {
    useJUnitPlatform()
    finalizedBy jacocoTestReport
}
jacocoTestReport {
    dependsOn test
    reports {
        xml.required.set(false)
        csv.required.set(false)
        html.required.set(true)
    }
}

azure-pipeline.yml:

// other tasks are skipped

      - task: Gradle@3
        displayName: 'Build by Gradle'
        inputs:
          gradleWrapperFile: 'gradlew'
          workingDirectory: '$(Build.SourcesDirectory)'
          tasks: 'build'
          codeCoverageToolOption: 'JaCoCo'
          codeCoverageClassFilesDirectories: 'build/classes/java/main/','build/classes/java/test/'
          javaHomeOption: 'JDKVersion'
          jdkVersionOption: '1.17'
          gradleOptions: '-Xmx3072m'
        env:
          SYSTEM_ACCESSTOKEN: $(System.AccessToken) # Use the system access token for authentication

// other tasks are skipped

@Hypertext-Assassin-RSS
Copy link

i have the same error any updates or workarounds

@templier2
Copy link

Hi, the problem is still here.
Please find time and take a look.

@emmanuels0n
Copy link

Hi, I'm having the same problem, locally it works perfect, the problem is when I use the gradle task on Azure DevOps

Gradle 8.2


* What went wrong:
A problem occurred evaluating root project 'clavedinamica-ms-security'.
> Could not set unknown property 'enabled' for Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport.

@templier2
Copy link

I have disabled the "Code Coverage" functionality from a Gradle Test task.
Instead, my colleague has added Jacoco section inside of build.gradle and configured a dependency for tests on it.
But yes, it is not working as expected and we spent a few days fixing it with SonarQube.

@SchulteMarkus
Copy link

Probable reason for this bug

The Gradle option 'enabled' on the 'Report' type mentioned here was removed in Gradle v8.0, which was released on Feb 13, 2023, see https://docs.gradle.org/8.0/userguide/upgrading_version_7.html#report_and_testreport_api_cleanup for details.
So I assume Gradle@3 has still not adapted this Gradle change.

Workaround
Let's get hands dirty and do it on our own.
Notes:

  • I didn't find a Cobertura plugin for Gradle, so sticking with JaCoCo
  • I didn't manage to get jacoco.exec working, so using XML JaCoCo coverage result
  1. Gradle with JaCoCo plugin and XML report
  1. In your DevOps pipeline additionally:
- task: PublishCodeCoverageResults@2
  inputs:
    summaryFileLocation: build/reports/jacoco/test/jacocoTestReport.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug Task: Gradle
Projects
None yet
Development

No branches or pull requests