首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从分级多项目构建构建一个完全可执行的SpringBoot1.3 war

从分级多项目构建构建一个完全可执行的SpringBoot1.3 war
EN

Stack Overflow用户
提问于 2015-12-04 12:47:27
回答 1查看 1.1K关注 0票数 1

我试图使用SpringBoot1.3构建一个完全可执行的WAR,如https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html所示。如果我构建一个单一的Gradle项目,它都可以正常工作,但是我有一个多项目构建,其中我有一个“根”项目,然后在它下面有几个项目,我无法让它构建任何东西,除了一个标准的、“胖”的WAR文件,没有Jetty的providedRuntime,也没有使它运行的脚本。

有人知道怎么做吗?

在我的根项目中,我有以下内容(节选):

代码语言:javascript
复制
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'
}

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

代码语言:javascript
复制
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,而不是可执行的WAR。

只要有一个项目,我就会让它运转良好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-04 13:29:19

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

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

代码语言:javascript
复制
classifier = environment.replaceAll(',','-')

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34088783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档