smithy icon indicating copy to clipboard operation
smithy copied to clipboard

Smithy gradle plugin dependency resolution can result in projects that won't build

Open jamesls opened this issue 3 years ago • 2 comments

Originally from https://github.com/aws-samples/smithy-server-generator-typescript-sample/issues/3#issuecomment-1176499412:

Yes, this is an unfortunate consequence of the way dependencies are resolved by the plugin and the project itself. When Smithy does a new release, it goes to mavenCentral immediately, and will be picked up by build dependencies immediately. Unfortunately, plugin dependencies are by default loaded from jcenter, which always lags behind maven central, and so if there is an incompatibility between the jcenter and mavenCentral Smithy libraries, you get errors like this.

For example, I am unable to build the example in the smithy-typescript README:

$ mkdir /tmp/samcheck && cd /tmp/samcheck
/tmp/samcheck $ cat > build.gradle.kts
 plugins {
     id("software.amazon.smithy").version("0.6.0")
 }

 repositories {
     mavenLocal()
     mavenCentral()
 }

 dependencies {
     implementation("software.amazon.smithy:smithy-model:[1.17.0, 2.0[")
     implementation("software.amazon.smithy.typescript:smithy-typescript-codegen:0.11.0")
 }
/tmp/samcheck $ cat > smithy-build.json
 {
     "version": "1.0",
     "plugins": {
         "typescript-codegen": {
             "service": "smithy.example#ExampleService",
             "targetNamespace": "SmithyExample",
             "package": "smithyexample",
             "packageVersion": "0.0.1",
             "packageJson": {
                 "license": "Apache-2.0"
             }
         }
     }
 }
/tmp/samcheck $ mkdir model && cat > model/main.smithy
namespace smithy.example

service ExampleService {
    version: "2022-01-01",
    operations: [Echo]
}

operation Echo {
    input: EchoInput,
    output: EchoOutput,
}

@input
structure EchoInput {
    message: String,
}

@output
structure EchoOutput {
    message: String
}
/tmp/samcheck $ gradle build
(detected Smithy CLI version [1.17.0, 2.0[)
Found an old version of Smithy CLI that does not support Cli#setStdout

> Task :smithyBuildJar FAILED
Running smithy build
'java.util.List software.amazon.smithy.model.traits.TraitDefinition.getBreakingChanges()'

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':smithyBuildJar'.
> 'java.util.List software.amazon.smithy.model.traits.TraitDefinition.getBreakingChanges()'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 910ms
1 actionable task: 1 executed

jamesls avatar Jul 06 '22 20:07 jamesls

I think my description of the cause in this case was inaccurate. The Gradle plugin is simply pulling in a new version of smithy-cli that is not compatible with the version resolved by the build file (the exception message you're getting is, I believe, from a NoSuchMethodError). We do see issues with plugin resolution being behind maven central resolution, but I don't think that's the case here.

In any event, the fix I used in https://github.com/aws-samples/smithy-server-generator-typescript-sample/pull/4 demonstrates, I think, that it's a matter of the smithy-cli version pulled in by the plugin being out of sync. I'm not sure how we solve it in the plugin itself off the top of my head.

adamthom-amzn avatar Jul 06 '22 20:07 adamthom-amzn

Not familiar with the gradle ecosystem at all, but if it's not possible to enforce compatible versions of smithy-cli between the plugin and the build file, perhaps it's possible to improve the error messages?

I don't mind having to dig around to figure things out, but don't think I would have ever figured out that a Caused by: java.lang.NoSuchMethodError: 'java.util.List software.amazon.smithy.model.traits.TraitDefinition.getBreakingChanges()' error message was due to incompatible smithy-cli versions. Anything that would've pointed me in that direction would have been helpful.

jamesls avatar Jul 06 '22 22:07 jamesls