Edit3: I was just complicating everything. Java so...
# gradle
e
Edit3: I was just complicating everything. Java source sets are registered through the usual Java extension, so
Copy code
java {
  sourceSets {
    main {
      java.srcDir("src/jvmMain/gen")
    }
  }
}
Edit2: not really working in case of Java sources sad panda Edit: I can answer myself
Copy code
kotlin {
  sourceSets {
    jvmMain {
      kotlin {
        srcDir("src/jvmMain/gen")
      }
    }
  }
}
Maybe dumb question, but how do I add a `gen`erated source folder, which will be ignored but part of the classpath, under
src/jvmMain
? The project is multiplatform.
v
You should not configure hard-coded paths like that though, as you will for example have to do task dependencies manually and must not forget any and so on. Usually, you make sure the task generating these sources has its outputs properly set and the use
srcDir(theTaskGeneratingTheSources)
then all consumers of source files automatically have the necessary task dependency too.
e
Thanks @Vampire! There is only a small issue tho. The
generateGrammarSource
task uses
outputDirectory
to register the task
outputs
That means the source set folder will be registered on the deepest package folder, e.g.
src/jvmMain/gen/com/my/pkg/parser
Can I override the
outputs
for that task after setting
outputDirectory
?
Copy code
generateGrammarSource {
  val `package` = "com/my/pkg/parser"
  val outputDir = "src/jvmMain/gen/$`package`"
  outputDirectory = projectDir.resolve(outputDir)
  arguments.add("-visitor");
  arguments.add("-long-messages");
}

java {
  sourceSets {
    main {
      java.srcDir(generateGrammarSource)
    }
  }
}
v
I think it should not be a problem. The compiler should not really care too much about the folder the file is in. That you use a directory structure that follows the package naming is purely convention. There might be some tools that cannot cope with it if the convention is not followed, but normally it should work just fine
e
Yup it works fine! It's just IDEA that disables inspections because it believes the package name doesn't match the folder structure.
v
Then you might consider having the package root folder as output dir. Just make sure you have no overlapping outputs of multiple tasks.
gratitude thank you 1