java9-modularity / gradle-modules-plugin

This Gradle plugin helps working with the Java Platform Module System
https://javamodularity.com/
MIT License
232 stars 36 forks source link

Support custom compilation taks #103

Open aalmiray opened 5 years ago

aalmiray commented 5 years ago

Currently the default compilation tasks for the main and test sourceSets are enhanced for Java, Kotlin, and Groovy following a strict name matching convention i.e these tasks are matched

It’d be great if additional compile tasks were enhanced too. This will likely require matching tasks by type (CompileJava for example). Another option is to inspect the properties of each SourceSet as they point to the compile tasks that affect said sourceSet.

This feature is needed by the GroovyFX project as it declares an extra sourceSet named demo https://github.com/groovyfx-project/groovyfx/blob/master/gradle/demo.gradle

aalmiray commented 4 years ago

This change is bigger than I thought as pretty much all tasks enriched by the plugin are found by name. This behavior poses 2 big problems:

  1. Only specific tasks get enriched. For example compileJava belonging to the main SourceSet but not compileDemoJava belonging to the demo SourceSet.
  2. Task search is performed eagerly, some tasks may fail to be found if the modules plugin is applied before others. This breaks the push Gradle has been doing in the past year to move most behavior to lazy evaluation.

In short, it'd be better if APIs such as project.task.withType(TaskType.class, { task -> }) be used instead as

  1. It matches tasks by type.
  2. Enables lazy evaluation.
big-andy-coates commented 6 months ago

I agree. It should also be possible to attach a listener to ensure any tasks created after the plugin is initialised also get detected as well. Happy to accept a PR.