我有一个多项目结构的项目。
project
subproject1
subproject2
....
在我的main
项目中,我添加了一些常规依赖项,subproject
中添加了特定的依赖项。
我的main
项目build.gradle
。
apply plugin: 'eclipse'
apply plugin: 'java'
allprojects {
group = 'com.app.pmc'
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.11'
}
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'net.saliman:gradle-liquibase-plugin:1.0.0'
classpath 'net.saliman:groovy-liquibase-dsl:1.0.0'
classpath 'org.postgresql:postgresql:9.3-1102-jdbc41'
classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
}
}
有一个创建 Web 应用程序的子项目。我这个项目的build.gradle
文件如下所示
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
dependencies {
compile project(':subproject-service')
compile 'org.springframework:spring-core:4.1.1.RELEASE'
compile 'org.springframework:spring-context:4.1.1.RELEASE'
compile 'org.springframework:spring-webmvc:4.1.1.RELEASE'
def tomcatVersion = '7.0.11'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
tomcat "org.apache.tomcat.embed:tomcat-embed-loggin-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
tomcat {
httpPort = 8080
httpsPort = 8081
}
}
但是当我尝试在我的子项目文件夹中运行gradle tR
时 - 我遇到了一个错误
FAILURE: Build failed with an exception.
* Where:
Build file 'D:projectsubproject-webbuild.gradle' line: 2
* What went wrong:
A problem occurred evaluating project ':subproject-web'.
> Could not create task of type 'TomcatRun'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
怎么了?
首先,
在dependencies
块中定义tomcat
配置闭包是无效的。其次,您还有一个无效的依赖项(loggin vs logging):
tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
您可以在下面找到一个工作脚本:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
}
}
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'org.springframework:spring-core:4.1.1.RELEASE'
compile 'org.springframework:spring-context:4.1.1.RELEASE'
compile 'org.springframework:spring-webmvc:4.1.1.RELEASE'
def tomcatVersion = '7.0.11'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
}
tomcat {
httpPort = 8080
httpsPort = 8081
}