gpt4 book ai didi

gradle - 如何创建父 build.gradle(具有通用配置)并从模块 build.gradle 调用它?

转载 作者:行者123 更新时间:2023-12-03 03:51:28 25 4
gpt4 key购买 nike

我有一个我正在用 gradle 编写的多模块项目。我想运行 findbugs、pmd、jococo 和 checkstyle 之类的测试以及一些对所有人都相同的配置,所以我想创建父 gradle 和模块 build.gradle 脚本。我不知道如何从模块 gradle 脚本调用父 build.gradle。有人可以给我一个例子,我怎么能做到这一点,这样我就不需要在每个模块中编写相同的东西。

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
apply plugin: 'maven'

//-- set the group for publishing
group = 'com.trxxxx.abcd'

/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.abcdBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.abcdBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.ngfh.abcd"
version = buildProperties.abcdBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

sourceCompatibility = 1.6
jar {
manifest {
attributes 'Implementation-Title': "${project.name}",
'Implementation-Version': "${project.version}",
'Implementation-Vendor-Id': "${project.group}"
}
}
repositories {

maven {
url "http://cmxxxxt.tsh.thon.com:80/ncds/cache"
}
}

dependencies {
compile ([
"com.eaio.uuid:uuid:3.2",
"org.springframework:spring-context:2.5.6",
"org.springframework:spring-beans:1.2.6" ,
"org.springframework:spring-core:1.2.3",
"org.springframework:spring-aop:3.0.6.RELEASE",
"org.springframework:spring-expression:3.0.7.RELEASE",
"org.projectlombok:lombok:1.12.2",
"com.fasterxml.jackson.core:jackson-core:2.1.3",
"com.fasterxml.jackson.core:jackson-annotations:2.2.3",
"com.fasterxml.jackson.core:jackson-databind:2.2.3",
"org.slf4j:slf4j-api:1.7.6",
"org.apache.commons:commons-lang3:3.0",
"junit:junit:4.+"
])
}

jacoco {
toolVersion = "0.7.1.201405082137"
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}

jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
executionData = fileTree(dir: 'build/jacoco', include: '**/*.exec')

reports {
xml{
enabled true
//Following value is a file
destination "${buildDir}/reports/jacoco/xml/jacoco.xml"
}
csv.enabled false
html{
enabled true
//Following value is a folder
destination "${buildDir}/reports/jacoco/html"
}
}
}

findbugs {
ignoreFailures = true
//sourceSets = [sourceSets.main]
}

pmd {
ruleSets = ["java-basic", "java-braces", "java-design"]
ignoreFailures = true
//sourceSets = [sourceSets.main]
}

checkstyle {
configFile = new File(rootDir, "config/checkstyle.xml")
ignoreFailures = true
//sourceSets = [sourceSets.main]
}

// adding test report to taskGraph
build.dependsOn jacocoTestReport

def pomFile = file("${buildDir}/libs/${archivesBaseName.toLowerCase()}-${version}.pom")
task newPom << {
pom {
project {
groupId project.group
artifactId project.name
version project.version
description = "Configuration Management Gradle Plugin"
}
}.writeTo(pomFile)
}
// adding pom generation to taskGraph
build.dependsOn newPom

//disabling the install task since we're not using maven for real
install.enabled = false

//for publishing to artifactory via jenkins
if(project.hasProperty('artifactoryPublish')) {
artifactoryPublish {
mavenDescriptor pomFile
}
}

// ------ Publish the jar file to artifactory ------
artifacts {
jar
newPom
}

最佳答案

如果您的多项目构建的所有项目都具有通用配置,那么您只需将其放在 allprojects { } 中即可。堵塞。

allprojects {
// place config that should be included in every project
}

关于gradle - 如何创建父 build.gradle(具有通用配置)并从模块 build.gradle 调用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29731380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com