<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Bryan

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks
    Once I provided some gradle scripts for building a runnable jar here, and now I tried to change them to gradle script kotlin and the following are the different versions of them

    Custom build(Building a runnable jar by the way "Copy required libraries into a sub-folder next to the generated Jar" in eclipse)


    //Builing a runnable jar by the way "Copy required libraries into a sub-folder next to the generated Jar"

    import org.gradle.jvm.tasks.Jar

    plugins {
        java
        eclipse
    }

    //profile configuration
    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)
        }
    }

    dependencies {
        compile("junit:junit:4.12")
    }

    repositories {
        jcenter()
    }

    //copy dependencies jars to a folder
    val copyDependencies = task<Copy>("copyDependencies") {
        from(configurations.compile)
        into("libs/lib")
    }

    //the jar tasks for building a runnable jar, 
    //and the denpendcies jars are in a folder next to the generated jar
    val jar: Jar by tasks
    jar.apply {
        dependsOn(copyDependencies)
        manifest.attributes.apply {
           put("Main-Class""samples.HelloWorld")
           
    if (!configurations.runtime.isEmpty()) {    
                put("Class-Path","./ lib/" + configurations.runtime.map{ it.name }.joinToString(" lib/"))
           }
        }
    }


    The following are differents ways of building runnable jar with spring boot gradle plugin and kotlin-dsl, and most of them I make the change according to the internet resources on stackoverflow and github.

    version1
    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"
    }

    //java {
        
    //sourceCompatibility = JavaVersion.VERSION_1_7
        
    //targetCompatibility = JavaVersion.VERSION_1_7
    //}

    dependencies {
        testCompile("junit:junit:4.12")
    }

    repositories {
        jcenter()
    }

    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") {
        
    //exclude shell scripts in profile folder
        if(project.hasProperty("env")){
            exclude("src/main/profile/scripts")
        }
    }

    //apply<SpringBootPlugin>()
    configure<SpringBootPluginExtension> {
        mainClass = "samples.HelloWorld"
    }

    inline fun <reified C> Project.configure(name: String, configuration: C.() -> Unit) {
        (this.tasks.getByName(name) as C).configuration()
    }


    version2

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

    //java {
        
    //sourceCompatibility = JavaVersion.VERSION_1_7
        
    //targetCompatibility = JavaVersion.VERSION_1_7
    //}

    dependencies {
        testCompile("junit:junit:4.12")
    }

    repositories {
        jcenter()
    }

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

    springBoot {
        mainClass = "Application"
    }

    inline fun <reified C> Project.configure(name: String, configuration: C.() -> Unit) {
         println(name + this.tasks.getByName(name));
        (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() }


    Version3
    //build a runnable jar with kotlin-dsl and spring boot gradle plugin, and It supports profiles,
    //any resource files related to different env can be placed in profile folder(env/stage/prod) 
    //and then run the command gradle.bat build -Penv=dev/stage/prod

    import org.springframework.boot.gradle.repackage.RepackageTask
    import org.gradle.language.jvm.tasks.ProcessResources

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

    //java {
        
    //sourceCompatibility = JavaVersion.VERSION_1_7
        
    //targetCompatibility = JavaVersion.VERSION_1_7
    //}

    dependencies {
        testCompile("junit:junit:4.12")
    }

    repositories {
        jcenter()
    }

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

    (tasks.getByName("processResources") as ProcessResources).apply {
        
    //exclude the shell scripts  if user used command with env like "gradle.dat build -Penv=dev"
        if(project.hasProperty("env")){
            exclude("src/main/profile/scripts")
        }
    }

    (tasks.getByName("bootRepackage") as RepackageTask).apply {
      mainClass = "demo.Application"
    }


    Reference
    https://github.com/gradle/kotlin-dsl/commit/b02916c7160ea45ad1bf7600d5a80c3bdaf6ceb9
    https://techdev.io/en/developer-blog/building-a-fat-jar-with-gradle-script-kotlin
    https://stackoverflow.com/questions/45399232/gradle-kotlin-is-it-possible-to-create-dynamic-on-fly-tasks
    https://stackoverflow.com/questions/39630897/how-to-configure-spring-boot-repackage-with-gradle-script-kotlin
    https://stackoverflow.com/questions/44741982/accessing-properties-of-a-task-in-gradle-kotlin
    https://stackoverflow.com/questions/40096007/how-to-configure-the-processresources-task-in-a-gradle-kotlin-build?rq=1
    https://github.com/kucharzyk/spring-kotlin-angular4/blob/master/build.gradle.kts
    https://github.com/gradle/kotlin-dsl/blob/master/build.gradle.kts
    https://stackoverflow.com/questions/41794914/how-to-create-the-fat-jar-with-gradle-kotlin-script?rq=1
    https://github.com/sdeleuze/spring-boot-kotlin-demo/blob/master/build.gradle.kts
    https://github.com/mixitconf/mixit/blob/master/build.gradle.kts
    https://github.com/gradle/kotlin-dsl/blob/master/build.gradle.kts
    https://github.com/mpecan/base_gradle_kts_newest/blob/master/build.gradle.kts
    https://github.com/gradle/gradle/blob/907a4e78989a1d7115020535ea0c0fc313d65b20/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaPluginConvention.java
    https://github.com/JLLeitschuh/springBootTesting/blob/da2d3be9bff22b50d6ba0b15bc0371eb6cc88b56/build.gradle.kts
    https://github.com/max-neverov/KMS/blob/a0239b9f8b82f72513b698a366209e8deb854893/build.gradle.kts
    https://github.com/kolyjjj/weed/blob/ce663f1a8606171e93e9f85092322191219abb97/build.gradle.kts
    https://github.com/gradle/kotlin-dsl/commit/b02916c7160ea45ad1bf7600d5a80c3bdaf6ceb9
    https://github.com/gradle/kotlin-dsl/blob/master/samples/copy/build.gradle.kts


    posted on 2017-08-29 10:05 Life is no respector of any genius. 閱讀(869) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 羞羞漫画小舞被黄漫免费| 亚洲中文字幕精品久久| 免费一级全黄少妇性色生活片 | 亚洲美女大bbbbbbbbb| 久久青草免费91观看| 亚洲精品狼友在线播放| a毛片久久免费观看| 亚洲精品夜夜夜妓女网| 99精品视频免费| 亚洲人成电影福利在线播放| 久久免费国产视频| 亚洲视频中文字幕在线| 亚洲精品免费在线| 亚洲精品综合在线影院| 在线永久免费观看黄网站| 噜噜综合亚洲AV中文无码| 免费a级毛片无码av| 男人扒开添女人下部免费视频| 精品国产日韩亚洲一区| 成人性生交大片免费看中文| 久久久久久亚洲精品成人| 两个人的视频高清在线观看免费| 久久精品国产亚洲AV天海翼| 亚洲熟女乱综合一区二区| 久久成人免费大片| 亚洲av片不卡无码久久| 99精品视频在线视频免费观看| fc2成年免费共享视频网站| 免费A级毛片无码A| 2017亚洲男人天堂一| 破了亲妺妺的处免费视频国产| 亚洲AV无码一区二区三区牲色| 日本高清免费不卡视频| 美女18毛片免费视频| 亚洲免费在线观看| 日韩电影免费在线观看网站| 91亚洲国产成人久久精品网站 | 丰满妇女做a级毛片免费观看| 亚洲熟妇无码乱子AV电影| 无码囯产精品一区二区免费| 亚洲人成黄网在线观看|