Как использовать скрипт gradle kotlin и плагин gradle для весенней загрузки, чтобы создать работающую флягу
У меня есть скрипт сборки gradle для создания работоспособного jar-файла (зависимости также являются jars-файлами) с плагином gradle для весенней загрузки, который работает нормально, и я хочу знать, как преобразовать его в kotlin-скрипт gradle. и я не знаю, как бороться с bootRepackage, профилем, а также processResources в kotlin. и поддерживается ли работа с плагином весенней загрузки gradle? Благодарю.
apply plugin: 'java'
apply plugin: 'eclipse'
buildscript {
repositories {
maven { url 'https://repo.spring.io/libs-milestone' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE'
}
}
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.6
targetCompatibility = 1.6
version = "1.0.0"
tasks.withType(JavaCompile) {
options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar"
}
if (project.hasProperty('env')) {
println "Target environment: $env"
sourceSets.main.resources.srcDir "src/main/profile/$env"
}
processResources{
exclude 'TagNames.properties'
}
repositories {
jcenter()
maven { url "http://clojars.org/repo" }
}
dependencies {
compile files('lib/jlibs-core.jar')
compile files('lib/jlibs-xml.jar')
compile files('lib/autonomyPiB.jar')
}
bootRepackage {
mainClass = 'com.test.TestA'
}
1 ответ
Я имею в виду ресурсы github и stackru, и кажется, что работает следующим образом, и любая проблема, пожалуйста, скажите мне обновить:
import org.springframework.boot.gradle.plugin.SpringBootPlugin
import org.springframework.boot.gradle.SpringBootPluginExtension
buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
repositories {
jcenter()
}
}
plugins {
java
eclipse
id("org.springframework.boot") version "1.5.6.RELEASE"
}
repositories {
maven {
url=uri("http://clojars.org/repo")
}
}
dependencies {
compile ("commons-net:commons-net:2.0")
compile ("log4j:log4j:1.2.17")
compile ("javax.servlet:servlet-api:2.4")
}
configure<JavaPluginConvention> {
setSourceCompatibility(1.7)
setTargetCompatibility(1.7)
if(project.hasProperty("env")){
var env = project.property("env");
sourceSets.getByName("main").resources.srcDirs("src/main/profile/" + env)
}
}
configure<ProcessResources>("processResources") {
if(project.hasProperty("env")){
exclude("src/main/profile/scripts")
}
}
//apply<SpringBootPlugin>()
configure<SpringBootPluginExtension> {
mainClass = "sample.HelloWolrd"
}
inline fun <reified C> Project.configure(name: String, configuration: C.() -> Unit) {
(this.tasks.getByName(name) as C).configuration()
}
другой способ работать:
import org.springframework.boot.gradle.SpringBootPluginExtension
configure<ProcessResources>("processResources") {
if(project.hasProperty("env")){
exclude("src/main/profile/scripts")
}
}
springBoot {
mainClass = "Application"
}
inline fun <reified C> Project.configure(name: String, configuration: C.() -> Unit) {
(this.tasks.getByName(name) as C).configuration()
}
/**
* Retrieves or configures the [springBoot] [org.springframework.boot.gradle.SpringBootPluginExtension] project extension.
*/
fun Project.springBoot(configure: org.springframework.boot.gradle.SpringBootPluginExtension.() -> Unit = {}) =
extensions.getByName<org.springframework.boot.gradle.SpringBootPluginExtension>("springBoot").apply { configure() }