【发布时间】:2018-03-06 00:12:33
【问题描述】:
你会认为这很容易。 Gradle/Maven 是专门为摆脱构建噩梦而设计的。然而......我已经搜索了网络,包括SO。我更喜欢使用 Maven,但这不是我能控制的。
我的主 build.gradle 文件如下所示:
buildscript {
repositories {
maven { url "https://aaa.com/xxxx/aaa-mvn" }
}
dependencies {
{redacted}
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: {redacted}
apply plugin: {redacted}
apply plugin: 'build-defaults'
apply plugin: 'module-plugin'
apply plugin: 'war'
description = 'xxxxxx'
defaultTasks 'build','install'
dependencies {
jbossModule(group: 'com.aaa.bbbb', 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(':xxxEAR').ear
}
}
}
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
这是我的 .war 的 gradle.build。我在 .ear 中有一个 .war。
description = 'Pricing'
buildscript {
repositories {
maven { url "https://xxx.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 {redacted}
classpath {redacted}
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jacoco'
apply plugin: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
apply plugin: 'maven'
apply plugin: 'maven-publish'
repositories {
maven { url "https://xxxx.aaa.com/artifactory/aaa-mvn" }
}
war {
archiveName 'xxxx.war'
}
dependencies {
compile {redacted}
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 {redacted}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
}
我的 .ear 的 build.gradle 文件是:
description = 'xxxxx'
buildscript {
repositories {
maven { url "https://xxxx.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: {redacted}
apply plugin: 'ucd-publish'
apply plugin: 'build-defaults'
apply plugin: {redacted}
configurations{
gen
}
dependencies {
deploy project (path: ":pricingWAR", configuration: 'archives')
earlib 'com.aaa.inf:inf-api-auth:1.4.+'
earlib {redacted}
earlib group: 'javax.security.enterprise', name: 'javax.security.enterprise-api', version: '1.0'
earlib (group: {redacted}) {
exclude group: 'javax.security.dddddd'
}
gen "io.swagger:swagger-codegen:2.2.2"
}
artifacts{
archives ear
}
repositories {
maven {
url "https://xxxx.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"
}
只是想这样做:将在我的业务类中编译的 .class 文件压缩成 .jar 并将它们添加到 EAR_file\lib。
我什至尝试使用 Gradle 的原生 Groovy 特性来编写构建 .jar 并将其移动到 EAR_file\lib 的代码。这当然是荒谬的。更糟糕的是,它并不完全有效。配合自动部署存在时间问题。
你们中的一些人无疑在畏缩。
为了让我免于这种疯狂,请告诉我你对此的了解。我当然尝试过以下各种排列:
apply plugin: 'java'
...
jar {
...
}
无济于事。
提前谢谢你。
【问题讨论】:
-
我已经几十年没有做过 EAR 文件了,所以不能给出明确的帮助,但是你看过这个示例项目吗? github.com/hammingweight/gradle-java-ear 这似乎是一个非常干净的实现?希望其他人有更多最近的经验......
-
@tim_yates 谢谢你的回复蒂姆,我会看看的。更新:不错,很干净,是的,但很少。我需要从业务类构建一个 .jar 并将其放入 EAR_file/lib 中,以便在部署时可以在通常从项目构建到 EAR_file/lib 文件夹的 .jar 文件中找到 .jar。这些将是 build.gradle 文件的 dependencies{} 部分中列出的依赖 .jar 文件。