Skip to content

Commit

Permalink
Add scala support (#104)
Browse files Browse the repository at this point in the history
Adds support for adding Smithy source files to Scala project jars.
  • Loading branch information
hpmellema committed Oct 10, 2023
1 parent 2fc3e9e commit e8e8bc3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 1 deletion.
16 changes: 16 additions & 0 deletions examples/jar-plugin/scala-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Example Project - Scala Project

This is an example Gradle Smithy project. In addition to serving as documentation,
this project is run as an integration test for the plugin.

This project demonstrates using the Smithy Gradle Plugin with a Scala project.
The Jar created by the Scala plugin will include the Smithy models built by the
`smithyBuild` task.

## Using the example as a starting point

Since this sample is run as an integration test, by default it is only configured
to use a locally published version of the plugin. To use this as a starting point
for your own project, uncomment the lines in `settings.gradle.kts` that configure
Gradle to use public sources.

15 changes: 15 additions & 0 deletions examples/jar-plugin/scala-project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This project adds smithy models to a JAR created by a Kotlin project

plugins {
scala
id("software.amazon.smithy.gradle.smithy-jar").version("0.8.0")
}

dependencies {
implementation("org.scala-lang:scala-library:2.13.11")
}

repositories {
mavenLocal()
mavenCentral()
}
5 changes: 5 additions & 0 deletions examples/jar-plugin/scala-project/model/main.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace smithy.example

structure Baz {
foo: String
}
9 changes: 9 additions & 0 deletions examples/jar-plugin/scala-project/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "scala-project"

pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
}
}
6 changes: 6 additions & 0 deletions examples/jar-plugin/scala-project/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"projections": {
"foo": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

object Main {
def main(args: Array[String]): Unit = {
println(greeting())
}

def greeting(): String = "Hello, world!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package software.amazon.smithy.gradle;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;

public class ScalaProjectTest {
@Test
public void testScalaProject() {
Utils.withCopy("jar-plugin/scala-project", buildDir -> {
BuildResult result = GradleRunner.create()
.forwardOutput()
.withProjectDir(buildDir)
.withArguments("clean", "build", "--stacktrace")
.build();

Utils.assertSmithyBuildTaskRan(result);
Utils.assertValidationRan(result);
Utils.assertArtifactsCreated(buildDir,
"build/smithyprojections/scala-project/source/build-info/smithy-build-info.json",
"build/smithyprojections/scala-project/source/model/model.json",
"build/smithyprojections/scala-project/source/sources/main.smithy",
"build/smithyprojections/scala-project/source/sources/manifest",
"build/libs/scala-project.jar");
Utils.assertJarContains(buildDir,
"build/libs/scala-project.jar",
"META-INF/smithy/manifest",
"META-INF/smithy/main.smithy",
"example/Main.class"
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class SmithyJarPlugin implements Plugin<Project> {
"android",
"android-library",
"org.jetbrains.kotlin.jvm",
"org.jetbrains.kotlin.android"
"org.jetbrains.kotlin.android",
"scala"
);
private boolean wasApplied = false;
private SmithyExtension extension;
Expand Down
10 changes: 10 additions & 0 deletions smithy-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
".gitignore"
]
},
"scala-project": {
"documentation": "Add Smithy models to a jar created by a Scala project.",
"path": "examples/jar-plugin/scala-project",
"include": [
"gradle/",
"gradlew",
"gradlew.bat",
".gitignore"
]
},
"multiple-jars": {
"documentation": "Build a Smithy JAR using both the java-library plugin and manually defined tasks.",
"path": "examples/jar-plugin/multiple-jars",
Expand Down

0 comments on commit e8e8bc3

Please sign in to comment.