本文介绍了难以为现有资源库布局设置Gradle多项目构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个Gradle多项目构建版本,以便我的项目布局已经完成。我有这样的东西:

   - > Shared\ 
----> SharedComponent1\
------> build.gradle
------> src\
...
----> SharedComponent2\
------> build.gradle
...
- >产品1 \
---->产品组件1 \
------> build.gradle
----> ProductComponent2\
------> build.gradle
...
----> build \
------> settings.gradle



我的settings.gradle看起来像这样:

  rootProject.name ='Product1'
rootProject.projectDir =新文件($ {ProjectsRoot})

include'Shared:SharedComponent1'
include'Shared:SharedComponent2'
include'Product1:ProductComponent1'
include' Product1:ProductComponent2'

当我在build文件夹中运行Gradle时:

  gradle -PProjectsRoot = c:\my\project\\ root \dir projects 

我得到:

 :项目

----------------------------- -------------------------------
根项目
--------- -------------------------------------------------- -

根项目'build'
无子项目

要查看项目任务列表,请运行gradle< project-path>:任务
例如,尝试运行gradle:任务

建立成功

即它找不到我正在尝试构建的项目。
我试图用Gradle的多项目支持来做什么?还是我吠叫错了树?

解决方案

几个指针:


  • Gradle严格将逻辑项目层次结构(Gradle将您的构建组织为项目的逻辑层次结构的方式)从物理目录布局。几乎任何映射都是可能的。 (想到的一个例外是,您不能让两个项目共享相同的项目目录。)

  • 要实现自定义目录布局,您必须将 projectDir 用于所有项目,而不仅仅是根项目。您应该使用相对路径,例如 rootProject.projectDir = new File(settingsDir,../ foo) project(:sub1)。projectDir = new File(rootDir ,bar)。在这里, settingsDir 引用包含 settings.gradle rootDir rootProject.projectDir

  • 要一般地配置项目,可以递归地遍历 (根)Project.children 。请注意, settings.gradle build.gradle 使用不同类型来表示项目 - 和。

  • Gradle必须从包含 settings.gradle 或其子目录。从可用性角度来看,最好将 settings.gradle 放入目录层次结构的根目录中。



有关详情,请参阅中的设置,以及一章。


I'm trying to craft a Gradle multiproject build for a situation in which my project layout is already dictated to me. I have something like this:

-->Shared\
---->SharedComponent1\
------>build.gradle
------>src\
...
---->SharedComponent2\
------>build.gradle
...
-->Product1\
---->ProductComponent1\
------>build.gradle
---->ProductComponent2\
------>build.gradle
...
---->build\
------>settings.gradle

My settings.gradle looks like this:

rootProject.name = 'Product1'
rootProject.projectDir = new File( "${ProjectsRoot}" )

include 'Shared:SharedComponent1'
include 'Shared:SharedComponent2'
include 'Product1:ProductComponent1'
include 'Product1:ProductComponent2'

When I run Gradle in the build folder like this:

gradle -PProjectsRoot=c:\my\project\root\dir projects

I get:

:projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'build'
No sub-projects

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :tasks

BUILD SUCCESSFUL

i.e. it doesn't find the projects I'm trying to build.Is what I'm trying to do possible with Gradle's multiproject support? Or am I barking up the wrong tree?

解决方案

A couple of pointers:

  • Gradle strictly separates the logical project hierarchy (the way Gradle organizes your build into a logical hierarchy of projects) from the physical directory layout. Just about any mapping is possible. (One exception that comes to mind is that you can't have two projects sharing the same project directory.)
  • To implement a custom directory layout, you'll have to set projectDir for all projects, not just the root project. You should use relative paths, e.g. rootProject.projectDir = new File(settingsDir, "../foo") and project(":sub1").projectDir = new File(rootDir, "bar"). Here, settingsDir refers to the directory containing settings.gradle, and rootDir is a shorthand for rootProject.projectDir.
  • To configure projects generically, you can recursively walk (root)Project.children. Note that settings.gradle and build.gradle use different types to represent a project - ProjectDescriptor and Project, respectively.
  • Gradle has to be invoked from the directory containing settings.gradle, or a subdirectory thereof. From a usability perspective, it is therefore best to put settings.gradle into the root of the directory hierarchy.

For more information, see Settings in the Gradle Build Language Reference, and the Multi-Project Builds chapter in the Gradle User Guide.

这篇关于难以为现有资源库布局设置Gradle多项目构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:09