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

Fixed build crash in gradle 8.0 #103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevalpatel2106
Copy link

closes: #102

Updated the jacocoTestReport properties from enabled to required as mentioned by Gradle documentation for plugin.

I tested the project builds on both Gradle 7.0.2 (current version in master) and Gradle 8.0.

@avalanchas
Copy link

avalanchas commented Mar 2, 2023

@kevalpatel2106 Thank you so much for this PR, it helps me get my own fork working. But one question, shouldn't line 88 to 101 in JacocoAndroidPlugin.groovy also be updated? The way it is now you still set the property on the plugin, right?

csv.enabled project.jacocoAndroidUnitTestReport.csv.enabled
html.enabled project.jacocoAndroidUnitTestReport.html.enabled
xml.enabled project.jacocoAndroidUnitTestReport.xml.enabled

@kevalpatel2106
Copy link
Author

@avalanchas Thanks for the feedback. This is my first time working with Gradle Plugin, so please bare me here.

I am making the following changes to reportTask

    reportTask.reports {
      def destination = project.jacocoAndroidUnitTestReport.destination
      
      csv.required project.jacocoAndroidUnitTestReport.csv.enabled
      html.required project.jacocoAndroidUnitTestReport.html.enabled
      xml.required project.jacocoAndroidUnitTestReport.xml.enabled

      if (csv.enabled) {
        csv.outputLocation new File((destination == null) ? "${project.buildDir}/jacoco/jacoco.csv" : "${destination.trim()}/jacoco.csv")
      }
      
      if (html.enabled) {
        html.outputLocation new File((destination == null) ? "${project.buildDir}/jacoco/jacocoHtml" : "${destination.trim()}/jacocoHtml")
      }

      if (xml.enabled) {
        xml.outputLocation new File((destination == null) ? "${project.buildDir}/jacoco/jacoco.xml" : "${destination.trim()}/jacoco.xml")
      }
    }

I also found that Report.destination is also deprecated and replaced with getOutputLocation. (So, I did something similar to this)

Does it look correct?


I tried running ./gradlew jacocoTestReport as mentioned in the readme and the task passed without these changes. Now I doubt the tasks did anything or not. Do you have any better method to test whether the merged reports are actually being generated?

@avalanchas
Copy link

Very nice that we can work together on this, I am also pretty new to this. Yes that looks correct to me, since ReportConfiguration still names the field enabled, so that should compile.

I was also just compiling this on a fork a second ago and saw that destination is crashing. I simply removed it to get it working but your solution is of course much better. I did not notice getOutputLocation before, is there any documentation for the migration you could link?

Hope that this can be merged soon

@kevalpatel2106
Copy link
Author

kevalpatel2106 commented Mar 2, 2023

@kevalpatel2106
Copy link
Author

@avalanchas Pushed new changes.

@arturdm Can you take a look at this PR? As the Gradle 8 adoption increases in the Android project, I think we will start getting more and more issues about plugin failing the build. I suggest we treat it as an urgent fix.

As I said above, very new to gradle plugins. So, happy to hear any suggestions.

@johnjohndoe
Copy link

@kevalpatel2106 Are you planning to take over maintenance and to publish your fork on Maven Central?

@tobiasKaminsky
Copy link

@kevalpatel2106 I applied your fork, but still I have:

by: org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed: No signature of method: org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.required() is applicable for argument types: (Boolean) values: [false]
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method required() for arguments [false] on Report csv of type org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.
	at org.gradle.internal.metaobject.AbstractDynamicObject$CustomMissingMethodExecutionFailed.<init>(AbstractDynamicObject.java:190)
	at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:184)
	at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:167)
	at org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport_Decorated.invokeMethod(Unknown Source)
	at io.github.kevalpatel2106.gradle.jacoco.android.JacocoAndroidPlugin$_createReportTask_closure2.doCall(JacocoAndroidPlugin.groovy:88)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
	at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
	at org.gradle.util.internal.ConfigureUtil.configureSelf(ConfigureUtil.java:131)
	at org.gradle.api.reporting.internal.DefaultReportContainer.configure(DefaultReportContainer.java:61)
	at org.gradle.api.reporting.internal.DefaultReportContainer.configure(DefaultReportContainer.java:35)
	at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:65)
	at org.gradle.testing.jacoco.tasks.JacocoReport.reports(JacocoReport.java:77)
	at org.gradle.testing.jacoco.tasks.JacocoReport.reports(JacocoReport.java:72)
	at org.gradle.testing.jacoco.tasks.JacocoReport.reports(JacocoReport.java:35)
	at org.gradle.api.reporting.Reporting$reports.call(Unknown Source)
	at 
------------------------------------------------------------
Gradle 8.0
------------------------------------------------------------

Build time:   2023-02-13 13:15:21 UTC
Revision:     62ab9b7c7f884426cf79fbedcf07658b2dbe9e97

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.19 (Oracle Corporation 11.0.19+7)
OS:           Linux 6.2.11-arch1-1 amd64

@gounthar
Copy link

Hello folks 👋
Is this repo abandoned, or can we hope this fix will be merged?

Thanks.

gounthar added a commit to gounthar/MyFirstAndroidAppBuiltByJenkins that referenced this pull request Apr 24, 2023
The Jacoco Android plugin is not yet compatible with Gradle 8.0, so I disabled it. We'll have to put it back after it's working again.
c.f. arturdm/jacoco-android-gradle-plugin#103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failing on Gradle 8.0
5 participants