我的項目中有類似的要求。我需要包含swf文件,這是flex項目的輸出到java項目並構建戰爭。
1. I created a two sub project under war project, flex and java.
2. Included them in settings file.
3. The main build.gradle file has basic configuration.
4. In flex sub project gradlefx plugin is applied and the output swf file is copied to the directory using a copy task.
5. In java sub project war plugin is applied and the source directory is mentioned from which war has to be generated.
這是給你參考的示例代碼:
設置。XML:在myproject的目錄
include myproject,
myproject:mysubproject:flex,
myproject:mysubproject:java
的build.gradle文件:在的myproject/mysubproject /柔性DIR
buildscript {
dependencies {
classpath project (":FlexProject") //include all the flex project from which the swf file to be included
}
}
dependencies {
classpath project (":JavaProject") //include all the dependent java project if any
}
sourceSets {
main {
output.classesDir = 'root/WEB-INF/classes' //This is the directory from which I am going to generate war.
}
}
的build.gradle文件:在myproject的
apply plugin: 'gradlefx'
type = 'swf'
dependencies{
merged project (":FlexProject")
}
String rootProjectDir = rootDir
rootProjectDir = rootProjectDir.replaceAll("\\\\","/")
task copyTask <<{
copy{
from rootProjectDir +'/MyFlexProject1/build'
into rootProjectDir +'/myproject/root'
include '**/*.swf'
}
}
build.finalizedBy(copyTask)
的build.gradle文件/ mysubproject/java目錄:
String rootProjectDir = rootDir
rootProjectDir = rootProjectDir.replaceAll("\\\\","/")
String rootProjectDirDocRoot = rootProjectDir + '/myproject/root'
dependencies {
compile project (":JavaProject") //to include dependent jars in war
}
group = "com.abc.enterprise"
archivesBaseName = "myprojet"
description = "myproject"
apply plugin: 'war'
war{
from rootProjectDirDocRoot
exclude('.gradle')
exclude('.settings')
}
這將每次編譯flex項目,他的swf文件將被包含在戰爭目錄中。希望這可以幫助。
它有幫助,謝謝! 但是,我可以創建項目之間的依賴關係,而不是任務? – 2013-02-14 20:17:22
不,你不能,在Gradle中沒有這樣的概念,你只能指定任務之間的依賴關係。你需要什麼項目依賴關係? – erdi 2013-02-14 20:42:47
謝謝,我不需要。我只是認爲,就像外部依賴關係一樣,我們定義了對構件的依賴性(即構建結果),就像我可以爲項目依賴性定義它一樣 - 即我的項目依賴於另一個項目構件(構建結果) – 2013-02-14 21:00:30