Skip to content

Commit bf7118a

Browse files
committed
Revert "Add a Gradle Plugin for codegen"
This reverts commit 24a9bd3. # Conflicts: # gradle-plugin/build.gradle.kts
1 parent ae320c3 commit bf7118a

19 files changed

Lines changed: 181 additions & 998 deletions

File tree

README.md

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,15 @@ and building services. These examples can be used as a template for a new projec
4242
4343
### Codegen (Gradle)
4444

45-
The recommended way to use Smithy Java code generation with Gradle is the
46-
[**Smithy Java Plugin**](./gradle-plugin/README.md), which handles dependency management,
47-
source set wiring, and task ordering automatically:
48-
49-
```kotlin
50-
// build.gradle.kts
51-
plugins {
52-
id("software.amazon.smithy.java.gradle.smithy-java") version "<smithy-java-version>"
53-
}
54-
```
55-
56-
Configure your [`smithy-build.json`](https://smithy.io/2.0/guides/smithy-build-json.html) with the
57-
`java-codegen` plugin:
58-
59-
```json
60-
{
61-
"version": "1.0",
62-
"plugins": {
63-
"java-codegen": {
64-
"service": "com.example#CoffeeShop",
65-
"namespace": "software.amazon.smithy.java.examples",
66-
"headerFile": "license.txt",
67-
"modes": ["client"]
68-
}
69-
}
70-
}
71-
```
72-
73-
That's it, run `./gradlew build` and the plugin takes care of the rest. See the
74-
[gradle-plugin README](./gradle-plugin/README.md) for full configuration options,
75-
examples (types-only, client, server), and escape hatches.
76-
77-
<details>
78-
<summary>Manual setup (without the Gradle plugin)</summary>
79-
80-
If you prefer manual control, apply [`smithy-base`](https://smithy.io/2.0/guides/gradle-plugin/index.html#smithy-gradle-plugins)
81-
directly:
45+
To use the Smithy Java code generators with Gradle, first create a Smithy Gradle project.
8246

8347
> [!NOTE]
8448
> You can use the `smithy init` [CLI](https://smithy.io/2.0/guides/smithy-cli/index.html) command to create a new
8549
> Smithy Gradle project. The command `smithy init --template quickstart-gradle` will create a new basic Smithy Gradle project.
8650
51+
Then apply the [`smithy-base`](https://smithy.io/2.0/guides/gradle-plugin/index.html#smithy-gradle-plugins) gradle plugin to
52+
your project.
53+
8754
```diff
8855
// build.gradle.kts
8956
plugins {
@@ -100,8 +67,28 @@ dependencies {
10067
}
10168
```
10269

103-
To compile the generated code as part of your project,
104-
add the generated package to your `main` sourceSet:
70+
Now, configure your [`smithy-build`](https://smithy.io/2.0/guides/smithy-build-json.html) to use one of the
71+
Smithy Java codegen plugins. For example, to generate a client for a `CoffeeShop` service we would
72+
add the following to our `smithy-build.json`:
73+
74+
```diff
75+
// smithy-build.json
76+
{
77+
...
78+
"plugins": {
79+
+ "java-codegen": {
80+
+ "service": "com.example#CoffeeShop",
81+
+ "namespace": "software.amazon.smithy.java.examples",
82+
+ "headerFile": "license.txt",
83+
+ "modes": ["client"]
84+
+ }
85+
}
86+
}
87+
```
88+
89+
Your project is now configured to generate Java code from our model. To execute a build run the
90+
gradle `build` task for your project. To compile the generated code as part of your project,
91+
add the generated package to your `main` sourceSet. For example:
10592

10693
```kotlin
10794
// build.gradle.kts
@@ -127,8 +114,6 @@ tasks.named("compileJava") {
127114
}
128115
```
129116

130-
</details>
131-
132117
### Stability
133118

134119
Classes and API's annotated with `@SmithyInternal` are for internal use by Smithy-Java libraries and should **not** be

examples/standalone-types/README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
## Examples: Standalone Types
22
Package that generates Java types for a model without a service.
33

4-
### Prerequisites
5-
This example depends on the `software.amazon.smithy.java.gradle.smithy-java` Gradle plugin, which must be
6-
available in a repository declared in `settings.gradle.kts`. If building from a local checkout
7-
before release, publish the plugin to Maven Local first:
8-
9-
```console
10-
./gradlew -p gradle-plugin publishToMavenLocal
11-
```
12-
134
### Usage
145
To use this example as a template, run the following command with the [Smithy CLI](https://smithy.io/2.0/guides/smithy-cli/index.html):
156

examples/standalone-types/build.gradle.kts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
12
plugins {
2-
id("software.amazon.smithy.java.gradle.smithy-java")
3+
`java-library`
4+
id("software.amazon.smithy.gradle.smithy-base")
35
}
46

57
java {
@@ -9,14 +11,43 @@ java {
911
}
1012

1113
dependencies {
14+
val smithyJavaVersion: String by project
15+
16+
smithyBuild("software.amazon.smithy.java:codegen-plugin:$smithyJavaVersion")
17+
api("software.amazon.smithy.java:core:$smithyJavaVersion")
18+
api("software.amazon.smithy.java:framework-errors:$smithyJavaVersion")
19+
1220
testImplementation("org.hamcrest:hamcrest:3.0")
1321
testImplementation("org.junit.jupiter:junit-jupiter:6.1.2")
1422
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
1523
testImplementation("org.assertj:assertj-core:3.27.7")
1624
}
1725

18-
tasks.withType<Test> {
19-
useJUnitPlatform()
26+
afterEvaluate {
27+
val typesPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-codegen").get()
28+
sourceSets {
29+
main {
30+
java {
31+
srcDir("$typesPath/java")
32+
}
33+
resources {
34+
srcDir("$typesPath/resources")
35+
}
36+
}
37+
}
38+
}
39+
40+
tasks {
41+
val smithyBuild by getting
42+
compileJava {
43+
dependsOn(smithyBuild)
44+
}
45+
processResources {
46+
dependsOn(smithyBuild)
47+
}
48+
withType<Test> {
49+
useJUnitPlatform()
50+
}
2051
}
2152

2253
repositories {

examples/standalone-types/gradle.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/standalone-types/settings.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
pluginManagement {
66
val smithyGradleVersion: String by settings
7-
val smithyJavaVersion: String by settings
87

98
plugins {
109
id("software.amazon.smithy.gradle.smithy-base").version(smithyGradleVersion)
11-
id("software.amazon.smithy.java.gradle.smithy-java").version(smithyJavaVersion)
1210
}
1311

1412
repositories {

0 commit comments

Comments
 (0)