1

I'm trying to build a fully executable WAR using Spring Boot 1.3 as per https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html. If I build a single Gradle project, it all works fine, but I havea multi project build, where I have a "root" project and then several projects underneath it, and I cannot get it to build anything but a standard, "fat" WAR file, without the providedRuntime of Jetty and without the scripts to make it run.

Does anyone know how to do this?

In my root project, I have the following (abridged):

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

and then in the subproject which is a web project, and which I'm trying to build, I have:

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

but when I build it (./gradlew build, or ./gradlew subprojectname:build), all is well and a working WAR is created, but not an executable one.

With a single project, I have it working fine.

4

1 回答 1

2

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

我完成了一个消除过程,结果发现问题区域是线

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

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

于 2015-12-04T13:29:19.540 回答