问题描述
我正在尝试制作多个项目的发布。根项目看起来像这样:
apply plugin:'distribution'
version 1.0
distributions {
main {
baseName ='someName'
contents {
from'nodes'
into'nodes'
}
}
}
它只是将一些文件夹复制到dist。
我现在希望每个子项目都将其内容注入dist。我想添加每个子项目jar,任何依赖项,还有其他一些文件等等。
我不知道如何从子项目注入到根目录。我应该甚至做这样的事情吗?我的意思是这样的:
子项目{
apply java ...
...
//伪代码
插入root项目dist插件
将我生成的jar和依赖关系放在一个名称为
...
}的文件夹中。
有没有人有任何例子,或者只是指出我的方向正确?
谢谢!
我在找同样的东西。有些人在API文档和Gradle自己的构建文件中偷看,我得出以下结论:
apply plugin:'distribution'
$ {
main {
contents {
into('bin'){
from {project(':subproject1')。startScripts.outputs .files}
from {project(':subproject2')。startScripts.outputs.files}
fileMode = 0755
}
into('lib'){
def libs = []
libs<< project(':subproject1')。configurations.runtime - project(':runner')。configurations.runtime
libs<< project'(':subproject2')。configurations.runtime $ b $ from libs
from project(':subproject1')。jar
from project(':subproject2')。jar
}
closure是 ,知道这使得使用分发插件的方式更简单:)
查看Gradle自己的子项目/ distributions / distributions.gradle文件,了解使用CopySpec的一些很好的例子。 / p>
这是有效的。
- 减法是删除重复的罐子。 >
- .jar行将添加该项目的jar作为配置。仅限运行时eem包含依赖关系。
不幸的是,目前我还不知道如何将这个扩展到两个以上的项目中办法。至少我们距离更近一步:)
I'm trying to make a dist of a multi project build. The root project looks something like this:
apply plugin: 'distribution'
version 1.0
distributions {
main {
baseName = 'someName'
contents {
from 'nodes'
into 'nodes'
}
}
}
It just copies a folder with some files to the dist.
I now want each subproject to inject its stuff into the dist. I want to add each subprojects jar, any dependecies, and possibly some other files etc...
I have no idea how to inject from the subproject to the root. Should I even do something like that? What i mean is something like this:
subprojects {
apply java...
...
// pseudocode
jack into the root project dist plugin
put my produced jars and dependencies in a folder with my name
...
}
Does anyone have any examples, or just point me in the right direction?
thanks!
I was looking for the same thing. With some peeking at the API docs and Gradle' own build files, I came to the following:
apply plugin: 'distribution'
distributions {
main {
contents {
into('bin') {
from { project(':subproject1').startScripts.outputs.files }
from { project(':subproject2').startScripts.outputs.files }
fileMode = 0755
}
into('lib') {
def libs = []
libs << project(':subproject1').configurations.runtime - project(':runner').configurations.runtime
libs << project(':subproject2').configurations.runtime
from libs
from project(':subproject1').jar
from project(':subproject2').jar
}
}
}
}
The contents {} closure is a CopySpec, knowing that makes using the distribution plugin way simpler :)
Check out Gradle' own subprojects/distributions/distributions.gradle file for some great examples of using the CopySpec.
This works.
- The substraction is to remove duplicated jars.
- The ".jar" lines are to add the jar of that project as the configurations.runtime only seem to contain the dependenceis.
Sadly, currently I've no clue on how to scale this to more than two projects in a clean way. Atleast we're one step closer :)
这篇关于Gradle多项目分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!