1

I have what seems to me like a very counter-intuitive dependency setup. I'm trying to author a gradle task that depends on the compilation of a (parallel) subproject. The problem is that when I execute the task it tries to compile the root project java/kotlin sources, which fails in my case.

How do I get a task to depend on a subproject compilation without causing the root project to compile first?

Here's my project structure

root-project/build.gradle
+-- parser/build.gradle
+-- lexer/build.gradle

An my lexer/build.gradle includes this task

task regenerateParser(type: JavaExec) {
    main 'org.intellij.grammar.Main'
    classpath project(':parser').sourceSets.main.runtimeClasspath

    def grammarFile = '../parser/schema/flatbuffers.bnf'
    def targetRoot = '../parser/src/gen/java'

    args targetRoot, grammarFile
}

But if I print the task graph, I get something that looks like this

:lexer:regenerateParser
+--- :classes
|    +--- :compileJava
|    |    +--- :compileKotlin
|    |    |    \--- :parser:jar
|    |    |         +--- :parser:classes
|    |    |         |    +--- :parser:compileJava
|    |    |         |    |    \--- :parser:compileKotlin
|    |    |         |    \--- :parser:processResources
|    |    |         |         \--- :parser:patchPluginXml
|    |    |         +--- :parser:compileKotlin *
|    |    |         +--- :parser:inspectClassesForKotlinIC
|    |    |         |    \--- :parser:classes *
|    |    |         \--- :parser:postInstrumentCode
|    |    |              \--- :parser:instrumentCode
|    |    |                   +--- :parser:classes *
|    |    |                   \--- :parser:compileKotlin *
|    |    \--- :parser:jar *
|    \--- :processResources
|         \--- :patchPluginXml
+--- :compileKotlin *
\--- :postInstrumentCode
     \--- :instrumentCode
          +--- :classes *
          \--- :compileKotlin *

The thing that confuses me is why :lexer:regenrateParser depends on :classes instead of :parser:jar directly. How do I get it to depend on :parser instead of the root project?

xaviersjs
  • 1,579
  • 1
  • 15
  • 25

0 Answers0