Skip to content

Clean up checker-qual module-info build configuration and avoid bare 'src/main' Eclipse workaround #2130

Description

@wmdietl

Problem Description

In checker-qual/build.gradle, the module_info source set is currently configured as:

sourceSets {
    main {
        java {
            exclude 'module-info.java'
        }
    }
    module_info {
        java {
            srcDirs ('src/main')
        }
    }
}

Setting srcDirs ('src/main') on module_info causes several drawbacks:

  1. IDE classpath collision: Gradle's eclipse plugin registers src/main alongside src/main/java as source folders in checker-qual/.classpath. Eclipse and VS Code (Eclipse JDT LS) reject nested source folders without mutual exclusion filters, producing a build error (Cannot nest 'checker-qual/src/main/java' inside 'checker-qual/src/main').
    To unblock IDEs, a workaround was added in root build.gradle (PR Improve VS Code and Eclipse support #1518) filtering out e.path == 'src/main' in eclipse.classpath.file.whenMerged.
  2. Duplicate compilation: Because srcDirs ('src/main') covers all source files under src/main, sourceSets.module_info.java contains all 363 Java files in checker-qual. compileJava9 therefore compiles all annotations under --release 9 before compileJava overwrites them with Java 8 bytecode.
  3. Task workarounds: Gradle creates auto-generated tasks for module_info (e.g., compileModule_infoJava), requiring workarounds like tasks.named('compileModule_infoJava') { enabled = false }.

Proposed Cleanups

Investigate cleaner alternatives to avoid generating the bare src/main source set and compiling the whole library twice:

  • Option 1 (Compile module-info.java directly): Remove sourceSets.module_info entirely. Register compileJava9 as a standalone task with source = files('src/main/java/module-info.java') and classpath pointing to sourceSets.main.output.classesDirs. This keeps module-info.java at src/main/java/module-info.java without moving files or introducing dummy source sets.
  • Option 2 (Relocate module-info.java): Move module-info.java to src/module_info/java/module-info.java (the default convention for sourceSets.module_info) or src/main/java9/module-info.java, avoiding nesting with src/main/java. Note trade-off: file divergence when merging from upstream typetools.
  • Option 3 (Localize Eclipse filter): If sourceSets.module_info is retained for upstream compatibility, localize the Eclipse entry removal to checker-qual/build.gradle rather than applying it globally in root build.gradle.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions