我的项目中有类似的要求。我需要将作为 flex 项目输出的 swf 文件包含到 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:
include myproject,
myproject:mysubproject:flex,
myproject:mysubproject:java
myproject 目录中的 build.gradle 文件:
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.
}
}
myproject/mysubproject/flex 目录中的 build.gradle 文件:
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)
myproject/mysubproject/java 目录中的 build.gradle 文件:
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 文件将包含在必须从中构建战争的目录中。希望这可以帮助。