你认为这很容易。 Gradle / Maven专门设计用于摆脱构建恶梦。然而......我已经搜索过网络,包括SO。我更喜欢使用Maven但是这不是我的控制。
我的master build.gradle文件如下所示:
buildscript {
repositories {
maven { url "https://repo.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath "com.aaa.plugin.gradle:module-plugin:1.+"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.4"
}
}
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: 'module-plugin'
apply plugin: 'war'
description = 'Pricing'
defaultTasks 'build','install'
dependencies {
jbossModule(group: 'com.aaa.inf', name: 'inf-jdbc', version: '3.0.2')
}
artifactory {
publish {
repoKey=version.endsWith("SNAPSHOT") ? 'aaa-mvn-dist-snapshots' : 'aaa-mvn-dist'
defaults {
publications('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact project(':svcEAR').ear
}
}
}
repositories {
maven { url "https://repo.aaa.com/artifactory/aaa-mvn" }
}
这是我的.war的gradle.build。我在.ear里面有一个.war。
description = 'Pricing'
buildscript {
repositories {
maven { url "https://repo.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath "com.aaa.plugin.gradle:sonarqube-quality-gates-plugin:1.+"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.+"
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jacoco'
apply plugin: 'org.sonarqube'
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: 'sonarqube-quality-gates'
apply plugin: 'maven'
apply plugin: 'maven-publish'
repositories {
maven { url "https://repo.aaa.com/artifactory/aaa-mvn" }
}
war {
archiveName 'pricing.war'
}
dependencies {
compile 'com.aaa.inf:inf-subject:3.2.0'
compileOnly group: 'javax', name: 'javaee-api', version:'7.0'
testCompile "junit:junit:4.12"
compile 'io.swagger:swagger-annotations:1.5.10'
compile(group: 'com.aaa.inf', name: 'inf-jdbc', version: '3.0.2', classifier: 'sources')
compile(group: 'com.aaa.inf', name: 'inf-throttle', version: '3.0.1')
compile(group: 'com.ibm.db2', name: 'db2jcc', version: '3.64.133')
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
}
我的.ear的build.gradle文件是:
description = 'Pricing'
buildscript {
repositories {
maven { url "https://repo.aaa.com/artifactory/aaa-mvn" }
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.5"
classpath "com.aaa.plugin.gradle:build-defaults-plugin:1.+"
classpath "com.aaa.plugin.gradle:ucd-publish-plugin:1.+"
classpath "com.aaa.plugin.gradle:openapi-generator-gradle-plugin:1.+"
}
}
apply plugin: 'ear'
apply plugin: 'maven'
apply from: 'build.local-jboss.gradle'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: 'openapi-generator-plugin'
configurations{
gen
}
dependencies {
deploy project (path: ":pricingWAR", configuration: 'archives')
earlib 'com.aaa.inf:inf-api-auth:1.4.+'
earlib 'com.aaa.inf:inf-service-accounts:3.0.0'
earlib group: 'javax.security.enterprise', name: 'javax.security.enterprise-api', version: '1.0'
earlib (group: 'org.glassfish.soteria', name: 'javax.security.enterprise', version: '1.0') {
exclude group: 'javax.security.enterprise'
}
gen "io.swagger:swagger-codegen:2.2.2"
}
artifacts{
archives ear
}
repositories {
maven {
url "https://repo.aaa.com/artifactory/aaa-mvn"
}
}
task cleanVolumes(type: Delete) {
delete fileTree(dir: "./volumes/deployments/")
}
task copyEar(type: Copy) {
tasks.cleanVolumes.execute()
from "build/libs"
into "${project.projectDir}/volumes/deployments"
fileMode = 0644
}
build.finalizedBy(generateSwagger)
swaggerConfig {
archive = ear.archivePath
outputFormat = "JSON"
outputPath = project.buildDir.toString() + "/swagger"
}
只是想做到这一点:.jar我的业务类中编译的.class文件,并将它们添加到EAR_file \ lib。
我已经尝试使用Gradle的本机Groovy特性来编写构建.jar的代码并将其移动到EAR_file \ lib中。这当然是荒谬的。更糟糕的是,它并没有完全奏效。与自动部署配对存在时间问题。
你们中的一些人无疑是在畏缩。
为了免除这种疯狂,请告诉我你对此的了解。我当然尝试了各种各样的排列:
apply plugin: 'java'
...
jar {
...
}
无济于事。
提前谢谢。
答案 0 :(得分:1)
最后让它在工友的有益输入后工作。对于其他人来说,这里最终的好处是:
在EAR项目级别的build.gradle中:
// My project is named: pricing-svc and the .war subproject is named pricing-svcAPI
dependencies {
deploy project (path: ":pricing-svcAPI", configuration: 'archives') // This was here already
earlib project(path: ":pricing-svcAPI", configuration: 'customJar') // This is new
}
在WAR项目级别的build.gradle中:
configurations {
customJar
}
task doJar(dependsOn:classes, type: Jar){
from sourceSets.main.output
include 'com/xyz/bank/pricing/dao/**' // See Note 1
}
artifacts {
customJar doJar
}
注1:我在我的情况下添加了这个修饰符b / c我只需要.jar中给定位置的.class文件,实际上必须排除所有其他文件。请注意,Gradle文档具有错误标识的修饰符“include”。他们称之为“包括”,但实际上它是“包括”。