Gradle和插件的把戏,用于多模块构建

huangapple go评论72阅读模式
英文:

Gradle and Plugin shenanigans, for multi-module builds

问题

我有一个多模块项目,使用Gradle构建了许多东西,包括一些AWS Lambda函数、一个Java(Spring Boot)微服务和一个ReactJS Web应用程序。

为此,我想生成一些Jacoco代码覆盖报告,以便及时了解情况。所以目前我有这个:

subprojects {
    apply plugin: 'jacoco'

    plugins.withType(JavaPlugin) {
        jacoco {
            toolVersion = "0.8.5"
        }
    }
}

这个"工作"。然而,如果我更改为这个:

subprojects {
    plugins.withType(JavaPlugin) {
        apply plugin: 'jacoco'

        jacoco {
            toolVersion = "0.8.5"
        }
    }
}

当尝试构建第一个Java项目时,Gradle会失败,非常困难。我的意思是我并不是特别介意,只是真的很奇怪,为什么必须将jacoco插件应用于没有任何Java代码的子项目。有人知道原因吗?

英文:

So I have a multi module project which builds a lot of stuff using gradle, including some AWS Lambda's, a Java (Spring Boot) microservice, and a ReactJS webapp.

To this end I would like to generate some Jacoco code coverage reports to keep on top of things. So currently I have this:

subprojects {
    apply plugin: 'jacoco'

    plugins.withType(JavaPlugin) {
        jacoco {
            toolVersion = "0.8.5"
        }
    }
}

Which "works". However if I change it to this:

subprojects {
    plugins.withType(JavaPlugin) {
        apply plugin: 'jacoco'

        jacoco {
            toolVersion = "0.8.5"
        }
    }
}

Gradle fails hard when it tries to build the first Java project. I mean I don't really mind, it's just really weird that you have to apply the jacoco plugin to subprojects that don't have any Java code in them. Anyone?

答案1

得分: 1

请看示例3(仅在特定子项目上应用插件)的文档链接:https://docs.gradle.org/current/userguide/plugins.html

也就是在您的情况下:

plugins {
  id 'jacoco' version '1.0.0' apply false
}

subprojects {
  if (name.startsWith('myjacostuff')) {
    apply plugin: 'jacoco'
  }

  plugins.withType(JavaPlugin) {
    jacoco {
      toolVersion = "0.8.5"
    }
  }
}
英文:

See Example 3 (Applying plugins only on certain subprojects) in the documentation https://docs.gradle.org/current/userguide/plugins.html

i.e. in your case:

plugins {
  id 'jacoco' version '1.0.0' apply false
}

subprojects {
  if (name.startsWith('myjacostuff')) {
    apply plugin: 'jacoco'
  }

  plugins.withType(JavaPlugin) {
    jacoco {
      toolVersion = "0.8.5"
    }
  }
}

huangapple
  • 本文由 发表于 2020年8月13日 19:08:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63393848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定