我有一个战争项目(项目 A),它对另一个包含共享库(项目 B)的项目有编译依赖项,但是我不希望项目 B 的传递依赖项包含在 WTP 部署中。
当我使用 gradle 生成 war 文件时,项目 B 的传递依赖项被忽略,但是 WTP 不断将所有库复制到 /WEB-INF/lib 目录中,因此我遇到了类加载器问题。
我试图忽略来自项目 B 的传递依赖项,使用transitive = false
并忽略exclude
依赖项和配置级别的特定依赖项,到目前为止没有成功,我找不到我做错了什么。
提前致谢。
我的配置如下:
项目A
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
repositories {
mavenLocal()
mavenCentral()
maven { // ext release
url "${artifactory_contextUrl}/ext-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs release
url "${artifactory_contextUrl}/libs-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs snapshot
url "${artifactory_contextUrl}/libs-snapshot-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
url "http://repository.springsource.com/maven/bundles/release" }
maven { // SpringSource Enterprise Bundle Repository - External Bundle Releases
url "http://repository.springsource.com/maven/bundles/external" }
maven { // SpringSource Enterprise Bundle Repository - SpringSource Library Releases
url "http://repository.springsource.com/maven/libraries/release" }
maven { // SpringSource Enterprise Bundle Repository - External Library Releases
url "http://repository.springsource.com/maven/libraries/external" }
}
group = 'com.thisproject'
sourceCompatibility = '1.6'
version = '1.6'
war {
baseName = 'ROOT'
archiveName = baseName+'.'+extension
destinationDir = file('build/')
}
task deployToFolder(dependsOn: 'war') << {
copy {
from war.archivePath
into "${deployFolder}"
}
}
task jenkinsTest{
inputs.files test.outputs.files
doLast{
def timestamp = System.currentTimeMillis()
test.testResultsDir.eachFile { it.lastModified = timestamp }
}
}
build.dependsOn(jenkinsTest)
configurations {
runtime.exclude group: 'commons-validator', module: 'commons-validator'
runtime {
transitive = false
}
}
dependencies{
providedCompile group: 'log4j', name: 'log4j', version: '1.2.16'
providedCompile group: 'org.springframework.security', name: 'org.springframework.security.web', version: '3.1.1.RELEASE'
providedCompile group: 'org.springframework.security', name: 'spring-security-config', version: '3.1.1.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-web', version: '1.0.2.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-core', version: '1.0.2.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-facebook', version: '1.0.1.RELEASE'
providedCompile group: 'org.springframework.social', name: 'spring-social-twitter', version: '1.0.2.RELEASE'
providedCompile group: 'spring-social-google', name: 'spring-social-google', version: '1.0'
providedCompile group: 'jstl', name: 'jstl', version: '1.2'
providedCompile group: 'org.springframework.security', name:'org.springframework.security.taglibs', version:'3.1.1.RELEASE'
compile(project(':projectB')) {
exclude module:'commons-validator'
transitive = false
}
providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
providedCompile group: 'javax.servlet', name: 'jsp-api', version: '2.0'
providedCompile group: 'org.springframework', name: 'org.springframework.transaction', version: '3.1.1.RELEASE'
providedCompile group: 'commons-validator', name: 'commons-validator', version: '1.2.0'
providedCompile group: 'commons-lang', name: 'commons-lang', version: '2.4'
providedCompile group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
providedCompile 'javax.persistence:persistence-api:1.0.2'
providedCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
}
eclipse {
project { natures 'org.springsource.ide.eclipse.gradle.core.nature' }
wtp {
component { deployName = 'ROOT' }
facet {
facet name: 'jst.web', version: '2.5'
facet name: 'jst.java', version: '1.6'
}
}
}
compileJava {
options.encoding = "UTF-8"
}
项目 B
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
repositories {
mavenLocal()
mavenCentral()
maven { // ext release
url "${artifactory_contextUrl}/ext-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs release
url "${artifactory_contextUrl}/libs-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // libs snapshot
url "${artifactory_contextUrl}/libs-snapshot-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
url "http://repository.springsource.com/maven/bundles/release"
}
maven { // SpringSource Enterprise Bundle Repository - External Bundle Releases
url "http://repository.springsource.com/maven/bundles/external"
}
maven { // SpringSource Enterprise Bundle Repository - SpringSource Library Releases
url "http://repository.springsource.com/maven/libraries/release"
}
maven { // SpringSource Enterprise Bundle Repository - External Library Releases
url "http://repository.springsource.com/maven/libraries/external"
}
}
group = 'com.thisproject'
sourceCompatibility = '1.6'
version = '1.7.26-SNAPSHOT'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
destinationDir = file('build/')
}
task deployToFolder(dependsOn: 'jar') << {
copy {
from jar.archivePath
into "${deployFolder}"
}
}
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
dependencies{
compile group: 'log4j', name: 'log4j', version: '1.2.16'
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
compile group: 'com.lowagie', name: 'itext', version: '2.0.8'
compile group: 'commons-codec', name: 'commons-codec', version: '1.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.4'
compile group: 'commons-io', name: 'commons-io', version: '1.4'
compile group: 'commons-validator', name: 'commons-validator', version: '1.2.0'
compile group: 'org.apache.axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'com.esendex', name: 'esendex.sdk', version: '1.0'
compile group: 'org.apache.lucene', name: 'lucene-core', version: '1.9.1'
compile group: 'org.apache.lucene', name: 'lucene-snowball', version: '1.9.1'
compile group: 'com.sun.jersey', name: 'jersey-client', version: '1.12'
compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.12'
compile group: 'com.sun.jersey.ri', name: 'jax-rs-ri', version: '1.12'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.2'
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.3.1.Final'
compile group: 'org.springframework', name: 'org.springframework.aop', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.beans', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.context', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.jdbc', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.orm', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.oxm', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.transaction', version: '3.1.1.RELEASE'
compile group: 'org.springframework', name: 'org.springframework.web.servlet', version: '3.1.1.RELEASE'
compile group: 'spring-social-jpa', name: 'spring-social-jpa', version: '0.0.1'
compile group: 'javax.xml.bind', name: 'jsr173_api', version: '1.0'
compile group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
compile group: 'com.googlecode.libphonenumber', name: 'libphonenumber', version: '4.1'
compile group: 'axis', name: 'axis', version: '1.4'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.2'
compile group: 'org.apache.tomcat', name: 'catalina', version: '6.0.35'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'javax.servlet', name: 'jsp-api', version: '2.0'
compile group: 'org.springframework.security', name: 'org.springframework.security.web', version: '3.1.1.RELEASE'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.0.1'
compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.0'
testCompile 'junit:junit:4.11'
testCompile group: 'org.springframework', name: 'org.springframework.test', version: '3.1.1.RELEASE'
testCompile 'mysql:mysql-connector-java:5.1.22'
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.10.Final'
testCompile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.10.Final'
testCompile 'org.hibernate:hibernate-validator:4.3.1.Final'
compile(group: 'com.paypal.sdk', name: 'merchantsdk', version: '2.2.98')
compile(group: 'com.paypal.sdk', name: 'paypal-core', version: '1.1.1')
}
compileJava {
options.encoding = "UTF-8"
}