Java 如何跨不同git存储库中的多个项目共享gradle任务

Java 如何跨不同git存储库中的多个项目共享gradle任务,java,gradle,Java,Gradle,我们有很多库,我们有以下代码段来配置相应的插件。我们希望避免代码重复,而是希望从可以在所有项目中共享的基础存储库中提取这些定义。这应该如何配置 checkstyle { showViolations = false ignoreFailures = true .. } pmd { .. } license { .. } spotless { .. } artifactory { .. } 通过一种简单的方法,您可以将构建脚本插件导入到其他构建脚本中,即使它们位于不同的位

我们有很多库,我们有以下代码段来配置相应的插件。我们希望避免代码重复,而是希望从可以在所有项目中共享的基础存储库中提取这些定义。这应该如何配置

checkstyle {
    showViolations = false
    ignoreFailures = true
..
}

pmd {
..
}

license {
..
}

spotless {
..
}

artifactory {
..
}

通过一种简单的方法,您可以将构建脚本插件导入到其他构建脚本中,即使它们位于不同的位置/不同的存储库中。我认为唯一必要的要求是,在最终构建项目的机器上,您可以访问这些存储库

假设您拥有包含主配置的GitHub存储库。
https://github.com/user/shared-gradle-config/blob/master/scriptPlugin.gradle

其中包括:

checkstyle {
    showViolations = false
    ignoreFailures = true
..
}

pmd {
..
}

...
现在确保在其他脚本中使用原始资源。每个存储库服务都有不同类型的链接。下面是GitHub的示例:

https://raw.githubusercontent.com/user/shared-gradle-config/master/scriptPlugin.gradle

在实际项目的Gradle构建脚本开始时,您必须包括远程脚本插件的应用程序:


// Application of shared remote Gradle script plguin with common configuration
// With this line all the checkStyle, PMD configuration and whatever you have declared in the script will be applied to current project
apply from: "https://raw.githubusercontent.com/user/shared-gradle-config/master/scriptPlugin.gradle"


// Whatever custom logic below
wrapper {
  version = "7.0.0"
  distributionType = Wrapper.DistributionType.ALL
}

...

当我试图理解如何以这种方式共享构建配置时,我制作了一个原型项目miself。也许它能帮助你。注意,它不是最终版本,仍在改进。

通过一种简单的方法,您可以将构建脚本插件导入到其他构建脚本中,即使它们位于不同的位置/不同的存储库中。我认为唯一必要的要求是,在最终构建项目的机器上,您可以访问这些存储库

假设您拥有包含主配置的GitHub存储库。
https://github.com/user/shared-gradle-config/blob/master/scriptPlugin.gradle

其中包括:

checkstyle {
    showViolations = false
    ignoreFailures = true
..
}

pmd {
..
}

...
现在确保在其他脚本中使用原始资源。每个存储库服务都有不同类型的链接。下面是GitHub的示例:

https://raw.githubusercontent.com/user/shared-gradle-config/master/scriptPlugin.gradle

在实际项目的Gradle构建脚本开始时,您必须包括远程脚本插件的应用程序:


// Application of shared remote Gradle script plguin with common configuration
// With this line all the checkStyle, PMD configuration and whatever you have declared in the script will be applied to current project
apply from: "https://raw.githubusercontent.com/user/shared-gradle-config/master/scriptPlugin.gradle"


// Whatever custom logic below
wrapper {
  version = "7.0.0"
  distributionType = Wrapper.DistributionType.ALL
}

...

当我试图理解如何以这种方式共享构建配置时,我制作了一个原型项目miself。也许它能帮助你。注意,它不是最终版本,仍在改进中。

编写一个插件。我想看看是否有一种方法可以共享常见的插件配置,而不是在每个repo中共享。有办法吗?写一个插件。写一个插件。我想看看是否有一种方法可以共享常见的插件配置,而不是在每个repo中共享。有办法吗?写一个插件。