Gradle - Exclude从War文件中提供了范围广告

时间:2015-07-05 02:03:39

标签: gradle build.gradle

Gradle似乎声称在构建war文件时它不包含providedCompile和providedRuntime作用域。

但是,当我使用下面的war配置进行构建时,一个名为" lib-provided"的文件夹。似乎包含所有提供的范围广角罐。如何将此功能限制为不包括提供的范围广角罐。

    configure(rootProject) {
    apply plugin: 'idea'
    apply plugin: 'spring-boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'java'

    targetCompatibility = 1.8
    sourceCompatibility = 1.8

    repositories {
        mavenCentral()
        mavenLocal()
        maven { url "https://repository.jboss.org/nexus/content/groups/public-jboss/" }
    }

    // Import Spring Boot's bom, spring-boot-dependencies
    dependencyManagement {
        imports {
            mavenBom 'org.springframework.boot:spring-boot-dependencies:1.2.5.RELEASE'
        }
    }


    // Override the spring-data-releasetrain.version property
    ext['spring-data-releasetrain.version'] = 'Fowler-SR1'

    dependencies {
        compile("org.springframework.boot:spring-boot-starter-actuator")
        compile("org.springframework.boot:spring-boot-starter-security")
............ Other Spring Boot based projects
        testCompile("org.springframework.boot:spring-boot-starter-test")

        compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:2.4.6")

......... Below are the "Provided" Scoped packages

        providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
        providedCompile("org.apache.tomcat.embed:tomcat-embed-jasper:8.0.23")
        providedCompile("org.hibernate:hibernate-core:4.3.7.Final")
        providedCompile("org.hibernate:hibernate-infinispan:4.3.7.Final")
        providedCompile("org.hibernate:hibernate-entitymanager:4.3.7.Final")
        providedCompile("org.hibernate:hibernate-validator:5.1.3.Final")
        providedCompile("org.hibernate:hibernate-search-orm:5.0.1.Final")
        providedCompile("org.hibernate.common:hibernate-commons-annotations:4.0.4.Final")
        providedCompile("org.infinispan:infinispan-core:7.1.1.Final")
        providedCompile("org.infinispan:infinispan-query:7.1.1.Final")

        testCompile("com.microsoft.sqlserver:sqljdbc41:4.1")
    }


    configurations {
        providedCompile

        // replaced with jcl-over-slf4j
        all*.exclude group: 'commons-logging', module: 'commons-logging'
        // replaced with log4j-over-slf4j
        all*.exclude group: 'log4j', module: 'log4j'
    }

}
war {
    baseName = 'abc'
    version =  '5.0.0-SNAPSHOT-' + + System.currentTimeMillis();
    doFirst {
        manifest {
            attributes("Implementation-Title": project.name, "Implementation-Version": version, "Implementation-Timestamp": new Date())
        }
    }
    webAppDirName = 'web'
    includeEmptyDirs false
    archiveName 'abc.war'
}

谢谢!

1 个答案:

答案 0 :(得分:0)

在以下配置中,Gradle 4.6 下面的任何一个都不会出现在War / WEB-INF lib中。

如果你有一个Ear build.gradle可以包含如下所示的条目,这将确保Ear / lib文件夹中的所有depndence jar。

如果输入以下内容,生成的Ear文件将包含.war文件,而War / lib文件夹将没有指定的依赖文件。

apply plugin: 'war'
earlib project(path: ':MyWebProject', configuration: 'compile')
deploy project(path: ':MyWebProject', configuration: 'archives')


apply plugin: 'war'
dependencies {

providedCompile('org.apache.logging.log4j:log4j-web') 
providedCompile('org.springframework.boot:spring-boot-starter-web') {
     exclude module: "spring-boot-starter-tomcat" 
}   

}