Make samples native build fully optional
- Add springShellSampleNative project property - Implement generic samples build logic in buildSrc - Fixes #873
This commit is contained in:
2
.github/workflows/e2e.yml
vendored
2
.github/workflows/e2e.yml
vendored
@@ -37,7 +37,7 @@ jobs:
|
||||
with:
|
||||
node-version: '16'
|
||||
- run: |
|
||||
./gradlew clean build nativeCompile -PspringShellSampleMusl=${{ matrix.musl }} -PspringShellSampleE2E=true
|
||||
./gradlew clean build nativeCompile -PspringShellSampleMusl=${{ matrix.musl }} -PspringShellSampleNative=true -PspringShellSampleE2E=true
|
||||
timeout-minutes: 30
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
@@ -18,14 +18,17 @@ ext {
|
||||
def properties = new Properties()
|
||||
properties.load(it)
|
||||
set("springBootVersion", properties["springBootVersion"])
|
||||
set("nativeBuildToolsVersion", properties["nativeBuildToolsVersion"])
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
|
||||
implementation "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
|
||||
implementation("org.springframework:spring-core")
|
||||
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.3.2'
|
||||
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.29.0'
|
||||
implementation "org.graalvm.buildtools:native-gradle-plugin:${nativeBuildToolsVersion}"
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
* Copyright 2022-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,21 +15,75 @@
|
||||
*/
|
||||
package org.springframework.shell.gradle;
|
||||
|
||||
import org.graalvm.buildtools.gradle.NativeImagePlugin;
|
||||
import org.graalvm.buildtools.gradle.dsl.GraalVMExtension;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.springframework.boot.gradle.dsl.SpringBootExtension;
|
||||
import org.springframework.boot.gradle.plugin.SpringBootPlugin;
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class SamplePlugin implements Plugin<Project> {
|
||||
|
||||
private static final String NATIVE = "springShellSampleNative";
|
||||
private static final String E2E = "springShellSampleE2E";
|
||||
private static final String MUSL = "springShellSampleMusl";
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(JavaPlugin.class);
|
||||
pluginManager.apply(ManagementConfigurationPlugin.class);
|
||||
pluginManager.apply(SpringBootPlugin.class);
|
||||
if (isEnabled(project, NATIVE)) {
|
||||
pluginManager.apply(NativeImagePlugin.class);
|
||||
customizeNative(project);
|
||||
}
|
||||
configureBootJar(project);
|
||||
configureBootBuildInfo(project);
|
||||
new JavaConventions().apply(project);
|
||||
}
|
||||
|
||||
private void configureBootJar(Project project) {
|
||||
if (isEnabled(project, E2E)) {
|
||||
project.getTasks().withType(BootJar.class, (bootJar) -> {
|
||||
String name = String.format("%s.%s", bootJar.getArchiveBaseName().get(),
|
||||
bootJar.getArchiveExtension().get());
|
||||
bootJar.getArchiveFileName().set(name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void configureBootBuildInfo(Project project) {
|
||||
SpringBootExtension extension = project.getExtensions().getByType(SpringBootExtension.class);
|
||||
extension.buildInfo(buildInfo -> {
|
||||
buildInfo.getExcludes().add("time");
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeNative(Project project) {
|
||||
project.getPlugins().withType(NativeImagePlugin.class).all(nativePlugin -> {
|
||||
configureGraalVmExtension(project);
|
||||
});
|
||||
}
|
||||
|
||||
private void configureGraalVmExtension(Project project) {
|
||||
GraalVMExtension extension = project.getExtensions().getByType(GraalVMExtension.class);
|
||||
if (isEnabled(project, MUSL)) {
|
||||
extension.getBinaries().getByName(NativeImagePlugin.NATIVE_MAIN_EXTENSION).buildArgs("--static",
|
||||
"--libc=musl");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEnabled(Project project, String property) {
|
||||
if (project.hasProperty(property)) {
|
||||
return Boolean.valueOf(String.valueOf(project.findProperty(property)));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ pluginManagement {
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id 'org.springframework.boot' version "$springBootVersion"
|
||||
id 'org.graalvm.buildtools.native' version "$nativeBuildToolsVersion"
|
||||
id 'com.gradle.enterprise' version "$gradleEnterpriseVersion"
|
||||
id 'io.spring.ge.conventions' version "$springGeConventionsVersion"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
plugins {
|
||||
id 'org.springframework.shell.sample'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
description = 'Spring Shell Sample Catalog'
|
||||
@@ -13,29 +11,3 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.awaitility:awaitility'
|
||||
}
|
||||
|
||||
springBoot {
|
||||
buildInfo {
|
||||
excludes = ['time']
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('springShellSampleE2E') && springShellSampleE2E.toBoolean()) {
|
||||
bootJar {
|
||||
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
|
||||
}
|
||||
}
|
||||
|
||||
graalvmNative {
|
||||
metadataRepository {
|
||||
enabled = true
|
||||
}
|
||||
binaries {
|
||||
main {
|
||||
if (project.hasProperty('springShellSampleMusl') && springShellSampleMusl.toBoolean()) {
|
||||
buildArgs.add('--static')
|
||||
buildArgs.add('--libc=musl')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
plugins {
|
||||
id 'org.springframework.shell.sample'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
description = 'Spring Shell Sample Commands'
|
||||
@@ -13,29 +11,3 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.awaitility:awaitility'
|
||||
}
|
||||
|
||||
springBoot {
|
||||
buildInfo {
|
||||
excludes = ['time']
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('springShellSampleE2E') && springShellSampleE2E.toBoolean()) {
|
||||
bootJar {
|
||||
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
|
||||
}
|
||||
}
|
||||
|
||||
graalvmNative {
|
||||
metadataRepository {
|
||||
enabled = true
|
||||
}
|
||||
binaries {
|
||||
main {
|
||||
if (project.hasProperty('springShellSampleMusl') && springShellSampleMusl.toBoolean()) {
|
||||
buildArgs.add('--static')
|
||||
buildArgs.add('--libc=musl')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
plugins {
|
||||
id 'org.springframework.shell.sample'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
description = 'Spring Shell Sample E2E'
|
||||
@@ -13,29 +11,3 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.awaitility:awaitility'
|
||||
}
|
||||
|
||||
springBoot {
|
||||
buildInfo {
|
||||
excludes = ['time']
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty('springShellSampleE2E') && springShellSampleE2E.toBoolean()) {
|
||||
bootJar {
|
||||
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
|
||||
}
|
||||
}
|
||||
|
||||
graalvmNative {
|
||||
metadataRepository {
|
||||
enabled = true
|
||||
}
|
||||
binaries {
|
||||
main {
|
||||
if (project.hasProperty('springShellSampleMusl') && springShellSampleMusl.toBoolean()) {
|
||||
buildArgs.add('--static')
|
||||
buildArgs.add('--libc=musl')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user