【问题标题】:Error-prone in Gradle multi-module projectGradle 多模块项目容易出​​错
【发布时间】:2021-04-20 21:42:08
【问题描述】:

如何为多模块 Gradle 项目中的某些模块启用易出错功能?我希望能够为多个模块(不是全部)打开易出错的功能。

【问题讨论】:

    标签: gradle errorprone


    【解决方案1】:

    您可以在buildSrc 中将此构建逻辑作为插件共享,并且仅将此插件应用于您的目标模块。

    例如官网https://docs.gradle.org/current/samples/sample_convention_plugins.html中的这个示例有两个插件和三个模块:

    ├── buildSrc
    │   ├── build.gradle
    │   ├── settings.gradle
    │   └── src
    │       └── main
    │           └── groovy
    │               ├── myproject.java-conventions.gradle
    │               └── myproject.library-conventions.gradle
    ├── internal-module
    │   └── build.gradle
    ├── library-a
    │   ├── build.gradle
    │   └── README.md
    ├── library-b
    │   ├── build.gradle
    │   └── README.md
    └── settings.gradle
    

    其中两个应用了myproject.library-conventions,只有一个应用了myproject.java-conventions 插件:

    // internal-module/build.gradle
    plugins {
        id 'myproject.java-conventions'
    }
    
    dependencies {
        // internal module dependencies
    }
    
    // library-a/build.gradle
    plugins {
        id 'myproject.library-conventions'
    }
    
    dependencies {
        implementation project(':internal-module')
    }
    
    // library-b/build.gradle
    plugins {
        id 'myproject.library-conventions'
    }
    
    dependencies {
        implementation project(':internal-module')
    }
    

    【讨论】:

      猜你喜欢
      • 2020-11-10
      • 1970-01-01
      • 2012-02-19
      • 2019-08-07
      • 2019-07-02
      • 1970-01-01
      • 2020-06-26
      • 2021-03-23
      • 1970-01-01
      相关资源
      最近更新 更多