我的项目中有类似的要求。我需要包含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