can not create RPM using gradle - java

I am new to java/gradle setup and was able to build a jar file using example provided here. Also implemented Jacoco code coverage tool on same.
But running into following issue
Unable to build an RPM, Tried ospackage-plugin but its just doesnt generates anything ( used example provided on plugin's github page )
Jacoco not generating highlighted source code html files ? Its generating till method breakdown like this but not able to generate individual source code files
My build.gradle file is as below
plugins {
id "nebula.ospackage" version "3.2.0"
}
apply plugin: 'nebula.ospackage'
apply plugin: 'java'
apply plugin: "jacoco"
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile 'org.testng:testng:6.8'
compile 'log4j:log4j:1.2.17'
}
sourceSets {
main {
java { srcDir 'src/main/java/' }
resources { srcDir 'src/main/resources' }
}
test {
java { srcDir 'src/test/java/' }
resources { srcDir 'src/test/resources' }
}
}
test {
// explicitly include or exclude tests
include 'src/test/java/**'
useTestNG{
useDefaultListeners = true
}
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
html.destination "${buildDir}/jacocoHtml"
}
}
jar {
baseName = 'smith'
version = '1.0'
manifest {
attributes 'Main-Class': 'src.main.java.HelloWorld '}
}
ospackage {
packageName = 'foo'
version = '1.2.3'
release = '1'
arch = I386
os = LINUX
}
// buildRpm and buildDeb are implicitly created, but can still be configured if needed
buildRpm {
arch = I386
}
The STDOUT is as following
project]$ /opt/gradle/bin/gradle build
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:jacocoTestReport
:check
:build
BUILD SUCCESSFUL
Total time: 11.258 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.9/userguide/gradle_daemon.html
Any pointers on whatever i am overlooking above will be highly appreciated.
Also feel free to let me know in case any standard/convention is not followed
Thanks

You need to run the buildRpm task.
gradle buildRpm
If you want this task to run when running gradle build just configure a dependency in your build.gradle file
build.dependsOn buildRpm

In addition you can add below variables in your rpm task to make your RPM more standard
requires('package name') //required package to run your RPM to be pre installed, will fail if it is not.
preInstall('path_to_file') //script to be executed before installing RPM
preUninstall('path_to_file') //script to be executed before uninstalling RPM
postInstall('path_to_file') //script to be executed after installing RPM
preUninstall('path_to_file') // script to be executed after uninstalling RPM
archiveName //the name you want to give to your RPM.
epoch //Epoch, defaults to 0
user //Default user to permission files to
permissionGroupdisplay
packageGroup
buildHost
summary
packageDescription
license
packager
distribution
vendor
url
type //type e.g. binary
//below three variables are used for signing of the RPM
signingKeyId
signingKeyPassphrase
signingKeyRingFile
sourcePackage
//if you want to include some files in your rpm
def fileToInclude = fileTree(dir:"pathToFile", include : "file" )
from (fileToInclude) {
fileMode 0500 // file level permission
into "installation Location" //locationToPlaceTheFile
}
for more details and e.g. refer this link

Related

Build and deploy JavaFX Applicationn with jlink

I have a script build.gradle, which created the IDEA development environment when creating a JavaFX project with Gradle support:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.4'
id 'org.javamodularity.moduleplugin' version '1.8.10' apply false
}
group 'com.prototype'
version '1.0'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
sourceCompatibility = '17'
targetCompatibility = '17'
}
application {
mainModule = 'com.prototype.simulationcrystalgrowth'
mainClass = 'com.prototype.simulationcrystalgrowth.SimulationApplication'
}
javafx {
version = '17.0.1'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.1')
implementation('com.dlsc.formsfx:formsfx-core:11.4.2') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.2.1') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('eu.hansolo:tilesfx:17.0.11') {
exclude(group: 'org.openjfx')
}
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
After the "build" task is completed, the "distributions" folder appears in the build folder. It contains a zip archive with the following contents:
The bin folder contains two scripts, sh and bat.
The lib folder contains, as I understand it, all the required jar modules.
If JAVA_HOME is installed on Java 17 in my environment, then when executing the bat script, my program starts.
I expected that jlink is a kind of analogue of a more user-friendly assembly and packaging of the application, which will help to create something like an exe application launcher.
I also noticed that there are no tasks related to jlink in build.gradle is not called during the build process using the "build" task.
I tried to run them myself, and I got the same error:
I am confused by the mention of the "distributions/app" path in build.gradle, I expect there should be something else after the build.
What am I doing wrong?
What should I get at the output using jlink ?
The problem is solved.
The exclude of the org.openjfx module was removed from all dependencies.
Useful links:
https://openjfx.io/openjfx-docs/#gradle
https://github.com/openjfx/samples
https://developer.tizen.org/development/articles/openjdk-and-openjfx-installation-guide

Gradle task --help printed to console instead of my application execution

This is my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.1.11.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example.ProjectJar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
jar {
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes("Main-Class": "com.example.ProjectJar.ProjectJar.FileSend" )
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile 'io.minio:minio:6.0.11'
}
But instead of execution of my main class that does have a main function, I get the following output:
Task :help
Welcome to Gradle 5.6.4.
To run a build, run gradle ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 43ms
What should I do to have my main class execute instead of this?
Try these :
gradle clean build
This command creates the spring-boot jar file to the build/libs directory or the target directory.
we can start our application by running the following command at the command prompt:
java -jar spring-boot-web-application.jar
Another way
./gradlew bootJar
This command creates the spring-boot jar file
To run the application is by executing the following Gradle command:
./gradlew bootRun

How to run shadow jar with a gradle task?

I want to run my app after building it with the shadow jar plugin.
build.gradle:
plugins {
id 'java'
id "org.jetbrains.kotlin.jvm" version "1.3.21"
id "com.github.johnrengelman.shadow" version "5.0.0"
}
group 'org.example.java'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
repositories {
jcenter()
}
dependencies {
compile "io.ktor:ktor-server-netty:1.1.3"
}
I also have a global init.gradle:
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "/Users/User/Builds/${rootProject.name}/${project.name}"
}
}
So now the fat jar can be built to my global build directory with the shadowJar task. But I want to be able to run and build it with just one run configuration in IntelliJ. How do I do that?
Maybe there is another way to let gradle redirect all my output to a global build directory. I don't want to configure each IntelliJ project with the same output path manually. Suggestions are welcome.
Thank you :)
You should not touch the buildDir property for achieving what you want.
Instead, you should create a JavaExec task that will start the application from the shadow jar.
If you want that execution to be at a different place than the default location of the generated jar, you should either change the output of the shadow task itself, and only that output or make your execution task depend on a copy task that would move the shadow jar around.
Something like:
shadowJar {
destinationDir = "/Users/User/Builds/${rootProject.name}/${project.name}"
}
task runApp(type: JavaExec) {
main = "your.main.Class
classpath = shadowJar.archiveFile // use archivePath before Gradle 5.1
}

How to make the gradle ShadowJar task also create sources and javadoc of its children?

I have a gradle project with 8 child projects and a configured shadowjar task to create an "all" jar. The toplevel project is setup to have dependencies to all its children, this tells shadowjar what to include:
project(':') {
dependencies {
compile project(':jfxtras-agenda')
compile project(':jfxtras-common')
compile project(':jfxtras-controls')
compile project(':jfxtras-icalendarfx')
compile project(':jfxtras-icalendaragenda')
compile project(':jfxtras-menu')
compile project(':jfxtras-gauge-linear')
compile project(':jfxtras-font-roboto')
}
}
shadowJar {
classifier = null // do not append "-all", so the generated shadow jar replaces the existing jfxtras-all.jar (instead of generating jfxtras-all-all.jar)
}
This works fine, but maven central is refusing the all jar, because it does not have an associated sources and javadocs jar.
How do I tell gradle to also generate the sources and javadoc? ShadowJar's documentation says it should do this by default.
The shadow plugin doesn't seem to have a feature of building a fat sources/javadocs jars.
Below, I provide a few short tasks (javadocJar and sourcesJar) that will build fat javadoc and source jars. They are linked to be always executed after shadowJar. But it has no dependency on the shadow jar plugin.
subprojects {
apply plugin: 'java'
}
// Must be BELOW subprojects{}
task alljavadoc(type: Javadoc) {
source subprojects.collect { it.sourceSets.main.allJava }
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
}
task javadocJar(type: Jar, dependsOn: alljavadoc) {
classifier = 'javadoc'
from alljavadoc.destinationDir
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from subprojects.collect { it.sourceSets.main.allSource }
}
shadowJar.finalizedBy javadocJar
shadowJar.finalizedBy sourcesJar
Note, the subprojects section is required, even if you already apply the java plugin inside your subprojects.
Also note, it doesn't include javadocs of the third party libraries your subprojects might depend on. But usually you wouldn't want to do it anyway, probably.
This is an old thread, but I'm posting my solution, as it's a lot easier than the above, and I've confirmed it works:
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'signing'
id 'maven-publish'
}
// If using Spring Boot, this is needed
jar.enabled = true
jar.dependsOn shadowJar
java {
withJavadocJar()
withSourcesJar()
}
// Remove the -all extension from the "fat" Jar, or it can't be used
// when published to Maven Central.
shadowJar {
archiveClassifier.set('')
}
// The contents of this section are described here:
// https://docs.gradle.org/current/userguide/publishing_maven.html
publishing {
publications {
jwtopaLibrary(MavenPublication) {
artifactId = 'jwt-opa'
artifacts = [ shadowJar, javadocJar, sourcesJar ]
pom {
// etc. ...
}
// Signs the `publication` generated above with the name `jwtopaLibrary`
// Signing plugin, see: https://docs.gradle.org/current/userguide/signing_plugin.html#signing_plugin
signing {
sign publishing.publications.jwtopaLibrary
}
It's not made clear anywhere, and the information needs to be collected in several places, but for the signing plugin to work, you need the short form hex key ID:
# gradle.properties
# The `signing` plugin documentation is less than helpful;
# however, this is the magic incantation to find the `keyId`:
#
# gpg --list-signatures --keyid-format 0xshort
#
# The key also needs to be distributed to public GPG servers:
#
# gpg --keyserver keyserver.ubuntu.com --send-keys 123...fed
#
# In all cases, we need to use the values from the `pub` key.
signing.keyId=0x1234abcde
Then, it's just a matter of running ./gradlew publish and magic happens (well, not really, you still have to go to Sonatype repository, do the "close & release dance", but you know, whatever).

Is it mandatory to define the java plugin to download the depdendency in gradle script?

I am writing the gradle script where I need to download the multiple jar files from artifactory I am using the apply plugin 'java' in gradle script and able to fetch those jar files from artifactory easily but if I apply this plugin it run the jar task automatically and creates the jar which I don't want.Is there a way to download the jar files from artifactory with/without using the java plugin so that jar task couldn't trigger.
apply plugin 'java'
apply plugin: 'base'
//-- set the group for publishing
group = 'com.abcdef.covery'
/**
* 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.coveryadBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.scoveryadBuildVersion
println "${version}"
//name is set in the settings.gradle file
group = "com.abcdef.discovery"
version = buildProperties.coveryadBuildVersion
println "Building ${project.group}:${project.name}"
repositories {
maven {
url "http://art.tsh.tho.com:90000/artifactory/services"
}
}
dependencies {
runtime "covery.services:AddService:1.0#jar"
runtime "covery.services:AddService:1.1#jar"
runtime "covery.services:Services:1.0#jar"
runtime "covery.services:Services:1.1#jar"
}
task copyDeps(type: Copy) {
from configurations.runtime
into 'services/discovery/services/'
}
output:Below shows few tasks which are running while using the java plugin in the script and if I don't use then it doesn't download the jar files from artifactory.
16:28:32 Building com.abcdefgh.discovery:cdad
16:28:33 [buildinfo] Properties file found at 'C:\Windows\TEMP\buildInfo429617857022686528.properties'
16:28:35 :copyDeps UP-TO-DATE
16:28:36 :deletebuild
16:28:37 :buildreportZip
16:28:38 :deleteGraphicsAssets
16:28:47 :unzip
16:28:47 :compileJava UP-TO-DATE
16:28:47 :processResources UP-TO-DATE
16:28:47 :classes UP-TO-DATE
16:28:47 :jar
16:28:47 :artifactoryPublish
16:28:47 Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/abcdefg/covery/cdad/03_00_00_183/cdad-03_00_00_183.zip
16:28:53 Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/abcdefl/covery/cdad/03_00_00_183/cdad-03_00_00_183.jar
You do not need to add the java plugin to download dependencies. If you do not have any java source files I would recommend that you use the baseplugin instead:
apply plugin: 'base'
repositories {
mavenCentral()
}
configurations {
nameOfMyConfiguration
}
dependencies {
nameOfMyConfiguration 'org.scala-lang:scala-library:2.10.4'
}
task zipMyStuff(type: Zip) {
from configurations.nameOfMyConfiguration
}

Categories

Resources