Search code examples
javagradlejavaagents

Gradle: Task with path not found in project


I have a gradle project with the following structure:

rootDir
|--agent-v1.0.0
   |--agent.jar
|--proj1
   |-- // other project files
   |--build.gradle
|--proj2
   |-- // other project files
   |--build.gradle
|--build.gradle

I would like to run test.jvmArgs = ['javaagent:agent-v1.0.0/agent.jar'] for all subprojects, so I wrote the following task in the root build.gradle:

subprojects {
    task cs {
        outputs.upToDateWhen { false }
        dependsOn test.jvmArgs = ['javaagent:../agent-v1.0.0/agent.jar']
    }
}

But this fails with:

Could not determine the dependencies of task ':proj1'.

Task with path 'javaagent:../agent-v1.0.0/agent.jar' not found in project ':proj1'.

I've tried this by putting the agent-v1.0.0 in both the root, and in each project, and it still fails. What am I missing?


Solution

  • Why are you wrapping that logic in a new task? And then passing the return from jvmArgs to dependsOn?

    Just configure the test tasks correctly:

    subprojects {
        tasks.withType(Test) {
            jvmArgs "-javaagent:${project.rootDir}/agent-v1.0.0/agent.jar"
        }
    }