0

I am trying to build an RPM Centos 7 package from java source via Gradle. I have a java multi project environment with a shared library and a Java application. Here is the filesystem:

|-- 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

The automation settings.gradle is:

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

the automation build.gradle is:

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')
    }
}

I would like to build the RPM from the metrics project including the datalib library in the RPM. I have written this Gradle build.gradle file but it doesn't work:

// 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'

The RPM I have doesn't contain the datalib library

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

How could I include my shared library?

Thanks

1 Answer 1

0

I found a solution for my problem. I post the solution here, maybe could help someone. The solution was to use a Gradle configurations api. My Gradle configuration became:

// 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'
        }
}

Hope this could help someone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.