2017-04-11 103 views
0

Gradle构建用于八个应用程序。Gradle多应用程序WAR构建文件拆分为单独的包含文件 - 'def'将其分解

目前,一切都倾倒在一个巨大的单build.gradle文件。

我想分解成每个应用程序WAR构建一个Gradle文件。

但是,它们都有很多'def'用法。 “def”用法的分享对我来说不起作用。

我已经在这读了,因为我不知道Groovy的 - 但“高清”不会起球,摇篮文件之间共享的东西时,似乎特例?

错误表明,“高清”重用不工作(这是罚款时,都在一个巨大的单一的build.gradle文件):groovy.lang.MissingPropertyException:由

没有造成财产:withSubsystemFiles类:org.gradle.api.internal.file.copy.SingleParentCopySpec

如何解决? (或...这是一个可怕的构建设计开放的替代办法,太?)

文件:的build.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 

文件:/gradle/foo_application.gradle

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... 
} 

文件:/gradle/bar_application.gradle

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... 
} 

文件:/gradle/include_def.gradle

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 

回答

1

include_def.gradle,定义copySpec这样的:

ext.withSubsystemFiles = copySpec { 
    //-- Copy SubsystemFiles 
} 
ext.withSpecialResources = copySpec { 
    //-- Copy SpecialResources 
} 
ext.withServiceContext = copySpec { 
    //-- Copy ServiceContext 
} 

如果你想在你的项目中定义额外的属性,你有使用ExtraPropertiesExtension

+0

完美,谢谢:) –

相关问题