从Gradle多项目构建中构建完全可执行的Spring Boot 1.3战争

时间:2015-12-04 12:47:27

标签: spring-boot executable-jar spring-boot-gradle-plugin

我试图按照https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html使用Spring Boot 1.3构建完全可执行的WAR。如果我构建一个单独的Gradle项目,它一切正常,但我有一个多项目构建,我有一个" root"项目,然后在它下面的几个项目,我不能让它建立任何东西,但标准,"脂肪" WAR文件,没有提供的JettyRuntime,也没有脚本使其运行。

有谁知道怎么做?

在我的根项目中,我有以下(删节):

buildscript {
    repositories {
        mavenCentral()
    }
    ext {
        springBootVersion = '1.3.0.RELEASE'
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
    }
}

allprojects {
    //Put instructions for all projects
    repositories {
        mavenCentral()  // jcenter is missing spring-orm.4.1.6.RELEASE jar file so try mavenCentral first
        jcenter {
            url "http://jcenter.bintray.com/"
        }
        maven { url 'http://repo.opensourceagility.com/release' }
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'spring-boot'
}

然后在作为网络项目的子项目中,我试图构建,我有:

apply plugin: 'war'

dependencies {
    // Include related projects
    compile project(':project-model')
    compile project(':project-dynamoDB')

    // Core Spring Boot - note version is set in main build.gradle file
    compile 'org.springframework.boot:spring-boot-starter-web'

    // Remove Tomcat (included in -web) and include Jetty instead
    providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'

    // Other Spring modules
    compile 'org.springframework.boot:spring-boot-starter-social-facebook'
    compile 'org.springframework.boot:spring-boot-starter-social-linkedin'
    compile 'org.springframework.social:spring-social-google:1.0.0.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-devtools'
    compile 'org.springframework:spring-context'
    compile 'org.springframework:spring-context-support'
}

configurations {
    providedRuntime.exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
    all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // exclude when using log4j 
}

springBoot {
    mainClass = 'rs.web.Weblication'
    executable = true   
}

bootRun {
    addResources = true
}

processResources {
    // exclude resources if they look like they're profile dependent but don't match the current env/profile
    eachFile { d ->
        if(d.name.endsWith('.xml') || d.name.endsWith('.yaml') || d.name.endsWith('.properties')) {
            //def fname = d.name.replaceFirst(~/\.[^\.]+$/, '')
            //if(fname.indexOf("-") > -1 && ! fname.endsWith("-" + environment)) {
            //  d.exclude()
            //} else {
            // replace @variables@ listed below in properties/config files
            filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
                    activeProfiles: environment
                ])
            //}
        }
    }
}

war {
    baseName = 'project-web'
    version = '1.0.0'
    manifest {
        attributes 'Implementation-Title': baseName,
                   'Implementation-Version': version
    }
    webXml = file('src/main/resources/web.xml')
    // rename the war task which has profiles appended from warName-profile,profile2.war
    // to warName-profile.profile2.war
    classifier = environment.replaceAll(',','-')
}

但是当我构建它(./gradlew build./gradlew subprojectname:build)时,一切都很好,并且创建了一个有效的WAR,但不是可执行的。

通过一个项目,我可以正常工作。

1 个答案:

答案 0 :(得分:2)

啊哈,好吧我构建了一个测试多项目构建,它运行正常,所以显然是上面的配置。

我经历了一个消除过程,结果发现有问题的区域是行

classifier = environment.replaceAll(',','-')

用于将带有环境变量的文件重命名为名称的一部分。这个过程似乎妨碍了脚本的添加;如果确实有必要,也许可以在之后应用。