2017-08-25 39 views
1

我有一個gradle構建腳本,用於構建可運行的jar(依賴性也是罐子),它使用彈簧啓動gradle插件,工作正常,我想知道如何將其轉換爲gradle腳本kotlin。我不知道如何處理bootRepackage,profile以及kotlin中的processResources。以及它是否支持與Spring Boot Gradle插件一起使用?謝謝。如何使用gradle腳本kotlin和spring啓動gradle插件來構建一個可運行的jar

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上和計算器資源,而且似乎工作方式如下任何問題,請告訴我更新:

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() } 
相關問題