Skip to content

Commit

Permalink
chore: build native example :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Dec 18, 2023
1 parent 1699cba commit 76247df
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 14 deletions.
1 change: 1 addition & 0 deletions .checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="(?:Javadoc.*)" files=".*[\\/]test[\\/].*"/>
<suppress checks=".*" files=".*[\\/]generated[\\/].*"/>
</suppressions>
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ The example module contains a Spring Boot application with a couple of commands.

- auto-discovery of `CommandBean` instances as well as `@ScanCommands`-annotated classes
- supports both interactive & non-interactive (CLI) commands

![cli](img/cli.png)

- support for Spring Shell features such as descriptions and command groups

![descriptions](img/descriptions.png)
Expand All @@ -25,6 +28,10 @@ The example module contains a Spring Boot application with a couple of commands.

![completions](img/completions.png)

- support for native builds

![native](img/native.png)

## limitations

- no intermediate executors (you can do `/cat add` and `/cat remove` but not `/cat`)
Expand Down
15 changes: 15 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
alias(libs.plugins.spotless)
Expand All @@ -15,6 +17,19 @@ dependencies {
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

java {
toolchain {
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
}
}

spotless {
kotlinGradle {
target("*.gradle.kts", "src/*/kotlin/**.gradle.kts", "src/*/kotlin/**.kt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ indra {
checkstyle(libs.versions.checkstyle.get())
}

tasks {
withType<JavaCompile> {
options.compilerArgs.addAll(listOf("-Xlint:-processing", "-Werror"))
}
}

spotless {
fun FormatExtension.applyCommon(spaces: Int = 4) {
indentWithSpaces(spaces)
Expand All @@ -31,6 +25,8 @@ spotless {
licenseHeaderFile(rootProject.file("HEADER"))
importOrderFile(rootProject.file(".spotless/cloud-spring.importorder"))
applyCommon()

targetExclude("**/generated/**")
}
kotlin {
licenseHeaderFile(rootProject.file("HEADER"))
Expand Down
29 changes: 29 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
plugins {
id("cloud-spring.base-conventions")
alias(libs.plugins.spring.plugin.boot)
alias(libs.plugins.graal.native.buildtools)
}

apply(plugin = "io.spring.dependency-management")

graalvmNative {
binaries.all {
resources.autodetect()
}
binaries {
getByName("main") {
sharedLibrary = false
mainClass = "org.incendo.cloud.spring.example.ExampleApplication"
useFatJar = true
javaLauncher =
javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
vendor = JvmVendorSpec.matching("GraalVM Community")
}
}
}
testSupport = false
toolchainDetection = false
}

java {
toolchain {
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
}
}

dependencies {
implementation(project(":cloud-spring"))
implementation(libs.cloud.annotations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ public class ExampleApplication {

private static final Logger LOGGER = LoggerFactory.getLogger(ExampleApplication.class);

/**
* Example application entrypoint.
*/
public ExampleApplication() {
}

/**
* Launches the example application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
import org.incendo.cloud.spring.SpringCommandManager;
import org.incendo.cloud.spring.SpringCommandSender;
import org.incendo.cloud.spring.annotation.CommandGroup;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.jline.PromptProvider;

/**
* Configuration for the example application.
Expand All @@ -49,4 +52,9 @@ public class ExampleConfig {
(annotation, builder) -> builder.meta(SpringCommandManager.COMMAND_GROUP_KEY, annotation.value()));
return annotationParser;
}

@Bean
@NonNull PromptProvider myPromptProvider() {
return () -> new AttributedString("cat-shell:>", AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW));
}
}
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[plugins]
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
spring-plugin-boot = { id = "org.springframework.boot", version.ref = "springBoot" }
graal-native-buildtools = { id = "org.graalvm.buildtools.native", version.ref = "graal" }

[versions]
springBoot = "3.1.6"
springBoot = "3.2.0"
spotless = "6.22.0"
ktlint = "1.0.1"
indra = "3.1.3"
checkstyle = "10.12.5"
kotlin = "1.9.20"
graal = "0.9.28"

checkerQual = "3.40.0"
apiguardian = "1.1.2"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Binary file added img/cli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/native.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76247df

Please sign in to comment.