Создание полностью исполняемой войны Spring Boot 1.3 из многопроектной сборки Gradle

Я пытаюсь создать полностью исполняемый файл WAR с использованием Spring Boot 1.3 в соответствии с https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html. Если я создаю один проект Gradle, все работает нормально, но у меня есть многопроектная сборка, где у меня есть «корневой» проект, а затем несколько проектов под ним, и я не могу заставить его построить что-либо, кроме стандартного, «жирного» WAR, без предоставленной среды выполнения Jetty и без сценариев для его запуска.

Кто-нибудь знает как это сделать?

В моем корневом проекте у меня есть следующее (сокращенно):

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, а не исполняемый.

С одним проектом у меня все работает нормально.


person Pete Storey    schedule 04.12.2015    source источник


Ответы (1)


Ага, хорошо, я построил тестовую сборку с несколькими проектами, и она работала нормально, так что это явно была конфигурация, указанная выше.

Я проработал процесс исключения, и оказалось, что проблемной областью была линия

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

который предназначен для переименования файлов с переменными среды как частью имени. Этот процесс, кажется, мешает добавлению сценария; возможно, его можно было бы применить позже, если это действительно необходимо.

person Pete Storey    schedule 04.12.2015