【问题标题】:Gradle - dont create parent build in multi module project [closed]Gradle - 不要在多模块项目中创建父构建[关闭]
【发布时间】:2014-10-15 23:51:28
【问题描述】:

我的项目结构如下:

┌project
│
├── build.gradle
├── module 1
│    │
│    ├── build.gradle
│    ├── module 1.1
│    └── module 1.2
│  
└── module 2
     │
     ├── build.gradle
     ├── module 2.1
     └── module 2.2

我的问题是我为项目、模块 1 和模块 2 创建了构建。但我不需要它们,我只需要从模块 1.1、1.2、2.1 和 2.2 构建。

在子模块 build.gradle:

project(":modules 1") {
    ext.buildables = [
            project(':modules-1:modules.1.1'),
            project(':modules-1:modules.1.2')]    
}

project(":modules-1:modules.1.1") {

    dependencies {
        ...
    }
}

在根 build.gradle 中:

subprojects {
    apply plugin: 'java'
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}

对此有什么想法吗?

编辑:

运行 gradle build 后,目录结构如下:

┌project
│
├── build.gradle
├── build (not wanted)
├── module 1
│    │
│    ├── build (not wanted)
│    ├── build.gradle
│    ├── module 1.1
|    |    |
│    |    └── build
│    └── module 1.2
|         |
│         └── build
│  
└── module 2
     │
     ├── build (not wanted)
     ├── build.gradle
     ├── module 2.1
     |    |
     |    └── build
     └── module 2.2
          |
          └── build

如何摆脱这些不想要的文件夹,它们里面都有大小为 1kb 的 jar。

【问题讨论】:

  • 对我来说这个问题还不清楚。
  • @Opal 看看现在是不是更不稳定了
  • 是的,现在好多了。也许这个链接会帮助你:forums.gradle.org/gradle/topics/… ?

标签: java build gradle


【解决方案1】:

感谢@Opal 提供this discussion 的链接。

allprojects 中添加了以下内容,它会跳过空罐子。

jar {
    onlyIf { !sourceSets.main.allSource.files.isEmpty() }
}

【讨论】:

  • 另一种选择是在构建完成后删除根级构建目录。这是我必须使用的解决方案,因为我在我保留在父模块源中的所有子模块之间共享了类,但是构建正在为父模块制作一个 JAR,它不应该存在。答案是让父 build.gradle 包含这个:gradle.buildFinished { project.buildDir.deleteDir() }。有关更多信息,请参阅此答案:stackoverflow.com/a/52556528/2386514
猜你喜欢
  • 1970-01-01
  • 2020-06-26
  • 2019-07-11
  • 1970-01-01
  • 2019-10-06
  • 2019-07-02
  • 2021-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多