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

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

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

    Bryan

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      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. 閱讀(870) 評論(0)  編輯  收藏

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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 免费无码一区二区| 99精品热线在线观看免费视频| 亚洲人成无码网WWW| 久久免费视频99| 亚洲色最新高清av网站| 亚洲精品无码AV中文字幕电影网站| 免费播放在线日本感人片| 国产香蕉九九久久精品免费| 精品国产日韩亚洲一区91| 亚洲av无码一区二区三区网站| 久久久久国产精品免费免费搜索 | 亚洲精品成a人在线观看夫| 亚洲国产午夜中文字幕精品黄网站| 免费91最新地址永久入口| 亚洲免费网站观看视频| 久久伊人久久亚洲综合| 久久99热精品免费观看动漫| 亚洲福利在线视频| 国产视频精品免费| 曰批视频免费40分钟试看天天| 亚洲一区精品中文字幕| 亚洲免费观看在线视频| 国产亚洲精品免费| 亚洲三级视频在线观看| 国产亚洲色婷婷久久99精品91| 人禽杂交18禁网站免费| 久久精品一本到99热免费| 日韩毛片免费一二三| 亚洲丰满熟女一区二区v| 亚洲精品无码午夜福利中文字幕| 免费高清国产视频| 黄页网站在线免费观看| 亚洲真人无码永久在线| 女人张腿给男人桶视频免费版| 免费人成激情视频在线观看冫| 美女被免费视频网站a| 亚洲中文字幕无码一去台湾| 亚洲av成人无码久久精品| 亚洲精品成人网久久久久久| 麻豆一区二区免费播放网站| 99久久久国产精品免费蜜臀|