Domanda

Hello there Gradle gurus! I'm seeking for your mighty experience and knowledge :)

I have a Gradle plugin that hooks a Jacoco agent to the jvm. Currently my code looks like this:

Task t = project.allTasks.getByPath(project.getName+":"+"test");
t.jvmArgs = ["-javaagent:"+jacocoAgentJar+"=destfile=" + coverageResultFile.getCanonicalPath()];

This is working fine but since dynamic properties are deprecated I want to somehow get rid of them. However... changing the code to t.ext.jvmArgs = ["-javaagent:"+jacocoAgentJar+"=destfile=" + coverageResultFile.getCanonicalPath()]; doesnt work.

Could someone please explain to me how am I supposed to hook the Jacoco agent to the jvm withought using this dynamic property?

Thanks

È stato utile?

Soluzione

If you get a "dynamic properties" warning here, there is likely something wrong with your code, and it's not just a style issue. For one thing, the use of getAllTasks (which, by the way, takes a boolean parameter) is inappropriate here. Instead, you should use project.tasks.getByName("test"), which can be abbreviated to project.tasks["test"] or even project.test. Or, if you want to catch all test tasks, project.tasks.withType(Test).

Altri suggerimenti

you can configure directly the test task in the build file adding a configuration closure like this:

test{

  jvmArgs "javaagent:"+jacocoAgentJar+"=destfile=" + overageResultFile.getCanonicalPath()"

}

Not a direct answer to your question, but you may want to look into the gradle-jacoco plugin.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top