jprante / gradle-plugin-jflex

A JFlex plugin for Gradle
Apache License 2.0
8 stars 6 forks source link

By default the plugin writes in src/main/java, not in build/<whatever> as said in the docs #17

Closed ogregoire closed 2 years ago

ogregoire commented 3 years ago

With just the plugin written in gradle and no sourceSets set, I run:

gradlew clean build

Then the Java generated files are written in src/main/java/.... That means in my source code, ready to be published on my VCS!

I would expect them to be written in ${project.buildDir}/generated/sources/jflex as mentioned in the documentation.

dobbsy commented 3 years ago

I understand your confusion - as someone who is not super familiar with Gradle it also took me some time to understand this - but the documentation actually states that the generated files are placed into the last java source directory of the same SourceSet as the JFlex files that are to be compiled. Only if there are no java source directories fo the source set in which the jflex files are found the plugin will use ${project.buildDir}/generated/sources/jflex instead. So if you don't add any java source directories to the "main" SourceSet and place your JFlex files into src/main/jflex, the plugin will place the generated files into src/main/java (if you use the java plugin for your project, which you probably do). If you want to change that behaviour, I suggest you add another java source directory to the "main" SourceSet. You can do that like this (at least when the Groovy DSL is used):

sourceSets {
    main {
        java {
            srcDir('src/main/generated')
        }
    }
}

This will add src/main/generated to the java SourceDirectorySet of the main SourceSet (as the last element) and thus JFlex will put its generated files there (of course, you can choose another directory instead).

(If you aren't aware what source sets are, I encourage you to read about them)

ogregoire commented 2 years ago

I disagree with @dobbsy's comment. Out of the box, many tools that generate files or classes do it in the build directory, not in the src one. Even the official Maven plugin for JFlex does it. I would really expect a plugin that generates in the most respectful way of the code, and with absolutely zero surprises.

jprante commented 2 years ago

The defaut behaviour is changed in 1.6.0

https://plugins.gradle.org/plugin/org.xbib.gradle.plugin.jflex

Writing in Java source directory can be re-enabled by a boolean flag, for example

jflex {
   verbose = true
   dump = false
   progress = false
   // enable legacy behavior of writing directly into Java source directory. Not recommended.
   writeIntoJavaSrc = true
}