Netflix / Netflix/dgs-codegen

All of `build/generated` is added to main sourceSet.

Open
#39 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

The plugin in it's default configuration adds the directory build/generated to the main sourceSet.

However, this is problematic, since this directory is already used as the output directory for other methods of code generation, like annotation processors.

I ran into this problem in a project where an annotation processor is used for the test sourceSet for which the generated code is placed in build/generated/sources/annotationProcessor.java/test.
Since these generated classes have dependencies which are only available in the test classpath, adding build/generated to the main sourceSet breaks the build process.

I'm able to work around this by changing the output directory for this plugin and manipulating the main sourceSet like so:

tasks.withType(com.netflix.graphql.dgs.codegen.gradle.GenerateJavaTask) {
    generatedSourcesDir = "${project.buildDir.absolutePath}/dgs-codegen"
}

sourceSets {
    main {
        java {
            def dirs = srcDirs
            dirs.remove(file("${project.buildDir.absolutePath}/generated"))
            srcDirs = dirs
            srcDir "${project.buildDir.absolutePath}/dgs-codegen/generated"
        }
    }
}

But I believe that it would be better if this plugin would put its generated sources in some sub directory of build/generated instead, where they don't interfere with other generated sources.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the plugin's default source-set configuration and the GenerateJavaTask mentioned in the issue. Check how generatedSourcesDir and build/generated are used, then verify that the plugin's generated sources no longer include unrelated annotation-processor output and that the reported test-source-set build can complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.