2017-08-25 1 views
1

Ich habe ein Gradle-Build-Skript zum Aufbau eines Runable Jar (Depenencies sind auch Gläser) mit Spring Boot Gradle Plugin, die gut funktioniert, und ich möchte wissen, wie man es in ein Großbuchstabenskript kotlin umwandelt. und ich weiß nicht, wie man mit bootRepackage, Profil sowie processResources in Kotlin beschäftigt. und ob es unterstützt wird, mit Spring Boot Gradle Plugin zu arbeiten? Vielen Dank.Wie Gradle Skript kotlin und Spring Boot Gradle Plugin verwenden, um ein lauffähiges Glas zu bauen

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' 
} 

Antwort

1

Ich beziehe mich auf Github und Stackoverflow-Ressourcen, und es scheint, die folgende Art und Weise funktioniert und jedes Problem erklären Sie mir bitte zu aktualisieren:

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() 
} 

eine andere Art und Weise zu funktionieren:

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() } 
Verwandte Themen