dgs-codegen icon indicating copy to clipboard operation
dgs-codegen copied to clipboard

gradle plugin not resolving dependencies properly

Open xenoterracide opened this issue 1 year ago • 3 comments

# libs.versions.toml
dgs-codegen = { id = "com.netflix.dgs.codegen", version = "6.+" }
// build.gradle.kts
buildscript { dependencyLocking { lockAllConfigurations() } }

plugins {
  `java-library`
  alias(libs.plugins.dgs.codegen)
}

dependencyLocking {
  lockAllConfigurations()
}

tasks.withType<GenerateJavaTask>().configureEach {
  packageName = "com.xenoterracide.controller.registration"
  language = "java"
}
Configuration cache state could not be cached: field `classpath` of task `:controller-registration:compileJava` of type `org.gradle.api.tasks.compile.JavaCompile`: error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultUnlockedConfiguration'
> Could not resolve all files for configuration ':controller-registration:compileClasspath'.
   > Resolved 'org.jetbrains:annotations:13.0' which is not part of the dependency lock state
   > Resolved 'org.jetbrains.kotlin:kotlin-stdlib:1.9.24' which is not part of the dependency lock state
   > Resolved 'com.netflix.graphql.dgs:graphql-dgs-platform:5.5.1' which is not part of the dependency lock state
   > Resolved 'com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.5.1' which is not part of the dependency lock state

calling dependencies --write-locks (with some output filters

     +--- com.graphql-java:graphql-java:19.2 FAILED
|    +--- com.graphql-java:graphql-java:19.2 FAILED
|    +--- com.graphql-java:graphql-java:22.0 FAILED
|    +--- com.graphql-java:graphql-java:22.1 FAILED
|    +--- com.graphql-java:graphql-java:{prefer 18.3} FAILED
|    |    +--- com.graphql-java:graphql-java:{strictly [19.2, 20[; prefer 19.2; reject 18.2} FAILED
+--- com.netflix.graphql.dgs:graphql-dgs-platform FAILED

I tried adding things like com.netflix.graphql.dgs:graphql-dgs-platform:5.5.1 to implementation but that didn't fix it.

xenoterracide avatar Jun 08 '24 19:06 xenoterracide

It would appear that I needed to add this, and that spring-boot-dependencies absolutely broke things

  implementation(platform(libs.dgs.platform.dependencies))
  implementation(libs.graphql.java)

note: those map to libs.versions.toml

dgs-platform-dependencies = { module = "com.netflix.graphql.dgs:graphql-dgs-platform-dependencies", version = "9.+" }
graphql-java = { module = "com.graphql-java:graphql-java" }

I think I tried using 5.+ first and had this problem... but I'm not certain.

could more about this please be added to the documentation? I'm fine with needing to add dependencies for the generated code but I'd like it to be documented. I'm not actually generally using DGS, was just going to use this plugin for spring-graphql.

xenoterracide avatar Jun 11 '24 18:06 xenoterracide

IMVHO, the codegen plugin shouldn't automatically add (e.g.)

+--- com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-shared-core:7.0.3
|    +--- com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:9.1.3

into implementation etc. Why should it, at all? It has a task it runs, and should have a separate configuration. Right now, however, it's polluting the main dependency scope with its transitives, making it really tricky to use in more complex scenarios - like exactly the one you describe e.g., i.e.

not actually generally using DGS, just us[ing] this plugin for spring-graphql [codegen] (precisely my use case ATM as well)

@xenoterracide the current solution is to either use (officially provided via https://github.com/Netflix/dgs-codegen/blob/master/graphql-dgs-codegen-gradle/src/main/java/com/netflix/graphql/dgs/codegen/gradle/CodegenPluginExtension.java#L29 & https://github.com/Netflix/dgs-codegen/blob/master/graphql-dgs-codegen-gradle/src/main/kotlin/com/netflix/graphql/dgs/codegen/gradle/CodegenPlugin.kt#L60 - yes, the 2nd one specifies the default value used to resolve the no-conf case... and it's true ATM)

codegen {
    clientCoreConventionsEnabled = false
}

or, if you want to just hack Gradle (I don't recommend, but always an option if the previous fails for any reason)

configurations.implementation {
    exclude("com.netflix.graphql.dgs.codegen", "graphql-dgs-codegen-shared-core")
}

One way or another, I don't understand why add those to implementation at all. That's not the responsibility of a codegen plugin IMVHO - and if anything, it should be an opt-in (with default setting of false), and not opt-out (as it is currently).

Also, you're right this is not properly documented ATM I think. I had to inspect the source and trace the dep changes to locate the switch, no mention of any of the extension props in https://netflix.github.io/dgs/generating-code-from-schema/ at all (and I guess that's the current core documentation we have for the plugin, right?)

FyiurAmron avatar Jan 16 '25 17:01 FyiurAmron

Just to be clear I'm not saying it should be added to implementation I'm saying that this isn't easy to make it work as documented. So either they should be added to implementation or it should be fixed such that this error doesn't happen; or the documentation should be fixed such that you don't run into this error.

xenoterracide avatar Jan 22 '25 20:01 xenoterracide