Gradle多应用程序WAR构建文件拆分为单独的包含文件--';def&x27;打破它
Gradle build用于八个应用程序 目前,所有内容都转储在一个巨大的build.gradle文件中 我正在尝试将它拆分为每个应用程序WAR构建的一个Gradle文件 然而,它们都有许多共同的“def”用法。“def”用法的共享对我不起作用 我读过这篇文章,因为我不知道Groovy——但“def”不会起作用,在Gradle文件之间共享东西时似乎是特例 错误表明“def”重用不起作用(当所有文件都在一个巨大的build.gradle文件中时,这是正常的): 原因:groovy.lang.MissingPropertyException:无此类属性:类为org.gradle.api.internal.file.copy.SingleParentCopySpec的子系统文件 如何解决?(或者……这是一个糟糕的构建设计吗?也可以选择其他方式。) 文件:build.gradleGradle多应用程序WAR构建文件拆分为单独的包含文件--';def&x27;打破它,gradle,groovy,Gradle,Groovy,Gradle build用于八个应用程序 目前,所有内容都转储在一个巨大的build.gradle文件中 我正在尝试将它拆分为每个应用程序WAR构建的一个Gradle文件 然而,它们都有许多共同的“def”用法。“def”用法的共享对我不起作用 我读过这篇文章,因为我不知道Groovy——但“def”不会起作用,在Gradle文件之间共享东西时似乎是特例 错误表明“def”重用不起作用(当所有文件都在一个巨大的build.gradle文件中时,这是正常的): 原因:groovy.lang.Mis
//etc....
if ("foo".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/foo_application.gradle"
}
if ("bar".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/bar_application.gradle"
}
//etc... lots more applications to build
apply from: "${rootDir}/gradle/include_def.gradle"
task fooApplicationWar(type: War) {
from "website/application_foo"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to fooApplicationWar
}
// etc...
}
apply from: "${rootDir}/gradle/include_def.gradle"
task barApplicationWar(type: War) {
from "website/application_bar"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to barApplicationWar
}
// etc...
}
def withSubsystemFiles = copySpec {
//-- Copy SubsystemFiles
}
def withSpecialResources = copySpec {
//-- Copy SpecialResources
}
def withServiceContext = copySpec {
//-- Copy ServiceContext
}
// etc... many many other 'def' that are common, shared by all application builds
文件:/gradle/foo_application.gradle
//etc....
if ("foo".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/foo_application.gradle"
}
if ("bar".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/bar_application.gradle"
}
//etc... lots more applications to build
apply from: "${rootDir}/gradle/include_def.gradle"
task fooApplicationWar(type: War) {
from "website/application_foo"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to fooApplicationWar
}
// etc...
}
apply from: "${rootDir}/gradle/include_def.gradle"
task barApplicationWar(type: War) {
from "website/application_bar"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to barApplicationWar
}
// etc...
}
def withSubsystemFiles = copySpec {
//-- Copy SubsystemFiles
}
def withSpecialResources = copySpec {
//-- Copy SpecialResources
}
def withServiceContext = copySpec {
//-- Copy ServiceContext
}
// etc... many many other 'def' that are common, shared by all application builds
文件:/gradle/bar\u应用程序。gradle
//etc....
if ("foo".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/foo_application.gradle"
}
if ("bar".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/bar_application.gradle"
}
//etc... lots more applications to build
apply from: "${rootDir}/gradle/include_def.gradle"
task fooApplicationWar(type: War) {
from "website/application_foo"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to fooApplicationWar
}
// etc...
}
apply from: "${rootDir}/gradle/include_def.gradle"
task barApplicationWar(type: War) {
from "website/application_bar"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to barApplicationWar
}
// etc...
}
def withSubsystemFiles = copySpec {
//-- Copy SubsystemFiles
}
def withSpecialResources = copySpec {
//-- Copy SpecialResources
}
def withServiceContext = copySpec {
//-- Copy ServiceContext
}
// etc... many many other 'def' that are common, shared by all application builds
文件:/gradle/include_def.gradle
//etc....
if ("foo".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/foo_application.gradle"
}
if ("bar".equals( project.getProperty('application') )) {
apply from: "${rootDir}/gradle/bar_application.gradle"
}
//etc... lots more applications to build
apply from: "${rootDir}/gradle/include_def.gradle"
task fooApplicationWar(type: War) {
from "website/application_foo"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to fooApplicationWar
}
// etc...
}
apply from: "${rootDir}/gradle/include_def.gradle"
task barApplicationWar(type: War) {
from "website/application_bar"
webInf{
with withSubsystemFiles
with withSpecialResources
with withServiceContext
// then many 'from' that are __unique__ to barApplicationWar
}
// etc...
}
def withSubsystemFiles = copySpec {
//-- Copy SubsystemFiles
}
def withSpecialResources = copySpec {
//-- Copy SpecialResources
}
def withServiceContext = copySpec {
//-- Copy ServiceContext
}
// etc... many many other 'def' that are common, shared by all application builds
在
include_def.gradle
中,如下定义您的copySpec:
ext.withSubsystemFiles = copySpec {
//-- Copy SubsystemFiles
}
ext.withSpecialResources = copySpec {
//-- Copy SpecialResources
}
ext.withServiceContext = copySpec {
//-- Copy ServiceContext
}
如果要在项目中定义额外属性,必须使用