我有一个Gradle多项目。
其中一个项目是Flex项目,它是使用gradleFx插件构建的。
第二个是war项目,我需要将Flex项目的SWF文件包含在战争中。
我添加
war {
from (project(":flex:FlexManager").buildDir) {into ('flash')}
}
它确实使SWF陷入战争,但只有当SWF已经存在时才会出现。
然后我希望gradle将在我的战争构建过程中构建:flex:FlexManager项目。所以我添加
dependencies {
....
runtime project(path : ':flex:FlexManager')
}
我发现在战争构建期间启动flex项目构建的唯一方法是
war {
...
dependsOn ':flex:FlexManager:build'
}
但它看起来不是最好的方式 - 我更喜欢定义项目依赖项而不是任务依赖项
答案 0 :(得分:2)
您需要更改的所有内容是指定要从任务或任务输出而不是目录中复制 - 这将在war任务和构建swf文件的任何任务之间注册隐式依赖关系。
表示构建swf文件的任务必须指定其输出。我快速浏览了GradleFx,遗憾的是,看起来compileFlex任务没有这样做。首先,您需要按以下方式指定任务的输出:
compileFlex {
outputs.dir project.buildDir
}
然后修改您的战争任务配置:
war {
from project(":flex:FlexManager").compileFlex {
into ('flash')
}
}
你可能也应该唠叨GradleFx开发人员为他们的任务添加输出。 :)
修改强>
从评论中的讨论中我了解到,您可以依靠项目工件来代替任务。最简洁的方法是创建自定义配置,向其添加依赖关系,然后在配置war任务时在from调用中使用它:
configuration {
flex
}
dependencies {
flex project(':flex:FlexManager')
}
war {
from configurations.flex {
into ('flash')
}
}
您也可以直接使用:flex:FlexManager
的存档或默认配置:
war {
from project(':flex:FlexManager').configurations.archives {
into ('flash')
}
}
答案 1 :(得分:0)
我的项目有类似的要求。我需要将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.
以下是供您参考的示例代码:
的settings.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文件将被包含在必须构建war的目录中。希望这会有所帮助。