-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Schema generator Gradle plugin #1385
Conversation
…rer, add metadata to annotation processor module
…`requireNotNull`)
A new generated diff is ready to view.
|
// FIXME Remove hardcoded versioning | ||
dependencies.add("ksp", "aws.sdk.kotlin:dynamodb-mapper-codegen:1.3.2-SNAPSHOT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking for ideas / suggestions on this. I can't seem to find a way to grab the sdkVersion
from build.gradle.kts
and use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our low-level codegen modules, we persist at build time a resource containing a version number and then later read it at runtime when we need the version. (Only works for JVM, obvs.) Would something similar work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I was considering and forgot we used this solution already. I think it would work here, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did end up working, thanks for the suggestion
gradlePlugin { | ||
plugins { | ||
create("dynamodb-mapper-schema-generator") { | ||
id = "aws.sdk.kotlin.hll.dynamodbmapper.schema.generator" | ||
implementationClass = "aws.sdk.kotlin.hll.dynamodbmapper.plugins.SchemaGeneratorPlugin" | ||
description = "Plugin used to generate DynamoDbMapper schemas from user classes" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: The Gradle documentation shows several additional metadata we could set about the plugin such as website URL, repository URL, display name, etc. Do we know how those are used? Is it worth setting them on this plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's displayed on Maven Central ("External Resources") in the sidebar. I can add them!
KSP plugin, for example: https://central.sonatype.com/artifact/com.google.devtools.ksp/com.google.devtools.ksp.gradle.plugin
// FIXME Remove hardcoded versioning | ||
dependencies.add("ksp", "aws.sdk.kotlin:dynamodb-mapper-codegen:1.3.2-SNAPSHOT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our low-level codegen modules, we persist at build time a resource containing a version number and then later read it at runtime when we need the version. (Only works for JVM, obvs.) Would something similar work here?
@Test | ||
fun `applies the plugin`() { | ||
val buildFileContent = """ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") version "2.0.0" | ||
id("aws.sdk.kotlin.hll.dynamodbmapper.schema.generator") | ||
} | ||
configure<aws.sdk.kotlin.hll.dynamodbmapper.plugins.SchemaGeneratorPluginExtension>{ } | ||
""".trimIndent() | ||
|
||
buildFile.writeText(buildFileContent) | ||
|
||
val result = GradleRunner.create() | ||
.withProjectDir(testProjectDir) | ||
.withArguments("--info", "build") | ||
.withPluginClasspath() | ||
.withGradleVersion("8.5") | ||
.forwardOutput() | ||
.build() | ||
|
||
assertContains(setOf(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE), result.task(":build")?.outcome) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opinion: This test/module may benefit from more dynamic versioning retrieved at runtime to avoid hardcoding things like the Gradle runner version, Kotlin version, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we would have a parameterized test with multiple versions of Kotlin and Gradle. I think it should be added in follow-on PRs, I will add a TODO here.
import java.io.File | ||
import kotlin.test.assertContains | ||
|
||
class SchemaGeneratorPluginTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Oh interesting—I was expecting your plugin tests to be another module sort of like dynamodb-mapper-annotation-processor-test. This looks like it works but I wonder if we miss anything by not having actual test modules as part of the overall Gradle project. Do you know if this is the recommended style of testing Gradle plugins and, if so, what tradeoffs it might have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using the Gradle TestKit which seemed recommended for testing plugins. I think having another test module would be another good test to have, I'll look at adding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another test package which consumes the plugin. It's basically a copy of dynamodb-mapper-annotation-processor-test without the manual KSP configuration. We can expand this as more features are added like codegen configuration.
publishing { | ||
publications { | ||
create<MavenPublication>("dynamodb-mapper-codegen") { | ||
from(components["java"]) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Elsewhere where we manually create Maven publications we also add the sources JAR as an artifact. Should we be doing that here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we should. It doesn't prevent using this package as a dependency but it might help with autocompletion/search in IDEs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worked for all of the new publications except the Gradle plugin, which seems to already publish the JAR.
Execution failed for task ':hll:dynamodb-mapper:dynamodb-mapper-schema-generator-plugin:publishDynamodb-mapper-schema-generator-pluginPublicationToMavenLocal'.
> Failed to publish publication 'dynamodb-mapper-schema-generator-plugin' to repository 'mavenLocal'
> Invalid publication 'dynamodb-mapper-schema-generator-plugin': multiple artifacts with the identical extension and classifier ('jar', 'sources').
@@ -80,7 +80,7 @@ if (project.NATIVE_ENABLED) { | |||
// Start by invoking the JVM-only KSP configuration | |||
dependencies.kspJvm(project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) | |||
|
|||
// Then we need to move the generated source from jvm to common. Gradle lacks a move task so we roll our own! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: I see we have a solution already but would this be useful here?
aws-sdk-kotlin/codegen/sdk/build.gradle.kts
Lines 175 to 178 in d13b314
copy { | |
from("$projectionOutputDir/src") | |
into("${it.destinationDir}/generated-src") | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find, that's a copy but we want to move the files in this case
Quality Gate failedFailed conditions |
A new generated diff is ready to view.
|
…lin (#1451) * initial poc commit of DynamoDB Mapper (#1232) * add support for Mapper initialization (#1237) * implement mapper pipeline (#1266) * initial implementation of codegen for low-level operations/types (#1357) * initial implementation of secondary index support (#1375) * Create new codegen module and refactor annotation processor to use it (#1382) * feat: add Schema generator Gradle plugin (#1385) * Fix plugin test package * add attribute converters for "standard" values (#1381) * fix: schema generator plugin test module (#1394) * feat: annotation processor codegen configuration (#1392) * feat: add `@DynamoDbIgnore` annotation (#1402) * DDB Mapper filter expressions (runtime components) (#1401) * feat: basic annotation processing (#1399) * add DSL overloads, paginators, and better builder integration for DDB Mapper ops codegen (#1409) * chore: split dynamodb-mapper-codegen into two modules (#1414) * emit DDB_MAPPER business metric (#1426) * feat: setup DynamoDbMapper publication (#1419) * DDB Mapper filter expressions (codegen components) (#1424) * correct docs * mark every HLL/DDBM API experimental (#1428) * fix accidental inclusion of expression attribute members in high-level DynamoDB Mapper requests (#1432) * Upgrade to latest build plugin version * fix: various issues found during testing (#1450) * chore: update Athena changelog notes for 1.3.57 (2024-10-18) release (#1449) * feat: update AWS API models * feat: update AWS service endpoints metadata * chore: release 1.3.60 * chore: bump snapshot version to 1.3.61-SNAPSHOT * feat: initial release of Developer Preview of DynamoDB Mapper for Kotlin * Fix Kotlin gradle-plugin version * fix: ddb mapper tests (#1453) * Bump build plugin version --------- Co-authored-by: Matas <lauzmata@amazon.com> Co-authored-by: aws-sdk-kotlin-ci <aws-kotlin-sdk-automation@amazon.com>
Issue #
Description of changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.