2017-04-11 35 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

完美,謝謝:) –

相關問題