使用Gradle构建基于sprint引导的项目时出现以下错误。我尝试使用--debug选项构建,但这导致了相同的错误,没有进一步的见解。
:clean
:compileJava
:processResources
Copy over the Env properties
Copy env properties from src/main/resources to C:\project-portal\build/resources/main/local.application.properties
:classes
:findMainClass
:war
Creating exploded war file :: C:\project-portal\build/project-portal
:bootRepackage FAILED
失败:构建因异常而失败。
无法推断&C; \ project-portal \ build \ libs \ project-portal'
的布局
'无法推断布局'是什么意思?谢谢!
更新#1以包含build.gradle:
<pre>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
def deployDir = ""
def configDir=""
def appWarName = "project-portal"
configurations.create('myConfiguration')
configurations.myConfiguration {
if("$appEnv"=='local') {
configDir=localConfigDir
deployDir=localDeployDir
} else if("$appEnv"=='uat') {
configDir=uatConfigDir
deployDir=uatDeployDir
}
println "Config Dir :: $configDir"
println "Deploy Dir :: $deployDir"
}
processResources {
doLast {
println "Copy over the Env properties"
copy {
println "Copy env properties from src/main/resources to $buildDir/resources/main/${appEnv}.application.properties"
from "src/main/resources/${appEnv}.application.properties"
into "$buildDir/resources/main/"
rename { filename -> filename.replace "${appEnv}.application.properties", 'application.properties'}
}
}
}
springBoot {
mainClass= "com.company.Application"
}
bootRepackage {
mainClass = 'com.company.Application'
}
jar {
baseName = 'project-portal'
version = ''
exclude('src/main/resources/*.properties')
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
//compile("org.springframework.boot:spring-boot-starter-parent")
//compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
//hibernate
//compile 'org.eclipse.persistence:javax.persistence:2.1.0'
compile 'org.hibernate:hibernate-entitymanager:4.3.8.Final'
compile 'org.hibernate:hibernate-core:4.3.8.Final'
compile 'org.jboss.logging:jboss-logging:3.2.1.Final'
compile 'org.springframework.data:spring-data-jpa'
//Security
compile("org.springframework.boot:spring-boot-starter-security")
compile 'mysql:mysql-connector-java:5.1.34'
//After bug
compile 'aspectj:aspectjweaver:1.5.4'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9-rc-1'
}
war {
archiveName="$appWarName"
doLast {
println "Creating exploded war file :: $buildDir/$appWarName"
ant.unzip(src: war.archivePath, dest: "$buildDir/$appWarName")
}
}
task copyJar(type: Copy) {
println "Copy lib to $buildDir/lib"
it.dependsOn jar
from "$buildDir/libs"
into "$buildDir/web"
}
task deployApp(type: Copy) {
println "Copy dependencyJar to $buildDir"
it.dependsOn copyJar
it.dependsOn war
from "$buildDir/$appWarName/WEB-INF/lib"
into "$buildDir/externalJars"
from "$buildDir/libs"
into "$buildDir/externalJars"
from "$buildDir/$appWarName"
into "$deployDir/$appWarName"
}
</pre>
答案 0 :(得分:2)
问题是由appWarName
变量的值引起的。您将其设置为project-portal
,Gradle的war
任务不会添加.war
扩展名,因此生成的war存档的全名为project-portal
,不带任何扩展名。< / p>
bootRepackage
任务尝试根据其扩展名确定文件的布局(请参阅source) - 并失败,因为没有扩展名。
修复很简单:
def appWarName = "project-portal.war"