gpt4 book ai didi

java - 从 java 多项目构建 Gradle rpm

转载 作者:行者123 更新时间:2023-12-01 16:58:50 25 4
gpt4 key购买 nike

我正在尝试通过 Gradle 从 java 源构建 RPM Centos 7 包。我有一个带有共享库和Java应用程序的java多项目环境。这是文件系统:

|-- automation
build.gradle
settings.gradle
|-- datalib
|-- build
|-- libs
datalib-1.0.jar
|-- src
|-- main
|-- it
|-- datalib
build.gradle
settings.gradle
|-- metrics
|-- build
|-- distributions
metrics-1.0.rpm
|-- libs
metrics-1.0.jar
|-- src
|-- main
|-- it
|-- metrics
build.gradle
settings.gradle

自动化settings.gradle是:

rootProject.name = 'automation'
include 'metrics'
include 'datalib'

自动化build.gradle是:

allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.11
targetCompatibility = 1.11

repositories {
mavenCentral()
}
}

subprojects {
version = '1.0'


dependencies {
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.1'
testImplementation 'junit:junit:4.12'
}

}

project(':metrics'){
dependencies{
implementation project(':datalib')
}
}

我想从 metrics 项目构建 RPM,包括 RPM 中的 datalib 库。我已经编写了这个 Gradle build.gradle 文件,但它不起作用:

// apply plugin: 'application'

plugins {
id "application"
id "nebula.ospackage" version "8.3.0"
id 'com.palantir.git-version' version '0.12.3'
}

dependencies {
testImplementation group: 'org.apache.commons', name: 'commons-csv', version: '1.6'
}

ospackage {
def details = versionDetails()
packageName = 'metrics'
license = 'Proprietary Software'
description = 'Events Analytics Software'
version = details.lastTag
release = details.commitDistance + 1 + '.' + details.gitHash
arch = X86_64
os = LINUX
type = BINARY
user 'root'
fileMode 0644
requires('java', '1.9', GREATER | EQUAL)
vendor 'xxx'
directory('/etc/metrics', 755)
from(jar.outputs.files) {
into '/usr/share/metrics'
}
from(':datalib:/build/libs') {
into '/usr/share/metrics'
}
}


// Define the main class for the application
mainClassName = 'it.fox.metrics.App'

我的 RPM 不包含 datalib

MacBook-Pro:distributions fox$ rpm -qlp metrics-1.0~471-262.f5ad4a18ca.x86_64.rpm
/usr/share/metrics
/usr/share/metrics/metrics-1.0.jar

如何包含我的共享库?

谢谢

最佳答案

我找到了解决问题的方法。我在这里发布解决方案,也许可以帮助某人。解决方案是使用 Gradle configurations API。我的 Gradle 配置变成:

// apply plugin: 'application'

plugins {
id "application"
id "nebula.ospackage" version "8.3.0"
id 'com.palantir.git-version' version '0.12.3'
}

dependencies {
testImplementation group: 'org.apache.commons', name: 'commons-csv', version: '1.6'
}

ospackage {
def details = versionDetails()
packageName = 'metrics'
license = 'Proprietary Software'
description = 'Events Analytics Software'
version = details.lastTag
release = details.commitDistance + 1 + '.' + details.gitHash
arch = X86_64
os = LINUX
type = BINARY
user 'root'
fileMode 0644
requires('java', '1.9', GREATER | EQUAL)
vendor 'xxx'
directory('/etc/metrics', 755)
from(configurations.runtimeClasspath) {
into '/usr/share/metrics'
}
}

希望这可以帮助别人。

关于java - 从 java 多项目构建 Gradle rpm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61545271/

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