intellij idea: generate MANIFEST.MF in gradle project - gradle

I have gradle project (spring boot app) imported in Intellij Idea. When building with gradle I generate MANIFEST.MF with
bootJar {
manifest {
attributes 'Implementation-Version': "${version}"
attributes 'Implementation-Title': "${project.name}"
attributes 'Manifest-Version': "1.0"
}
}
however when running and building with Intellij manifest file is not generated (out/production/classes/META-INF) and in application getClass().getPackage().getImplementationVersion() is null
How can I generat manifest with Intellij?

Related

Generate MANIFEST.MF using Spring Boot and Gradle

I need to add the following headers to the MANIFEST.MF file using Gradle and Spring Boot:
Name
Specification-Title
Specification-Version
Specification-Vendor
Is there a way to configure the Gradle build process to read these values from settings.gradle and build.gradle and write them to the MANIFEST.MF file?
Writing them to the manifest file is described here: add manifest file to jar with gradle
To populate these values from settings.gradle and gradle.properties, consider the following:
build.gradle
plugins {
id "idea"
id "java"
}
jar {
manifest {
attributes 'Specification-Title': gradle.ext.jonesVar
attributes 'Specification-Version': bibibi
}
}
settings.gradle
gradle.ext.jonesVar = "jones"
gradle.properties
bibibi=3
The result from ./gradlew clean build gives build/libs/tmp.jar containing this manifest:
MANIFEST.MF
Manifest-Version: 1.0
Specification-Title: jones
Specification-Version: 3
If you need to do this for the bootJar, use bootJar { instead of jar { in your build.gradle.

NoClassDefFoundError in EXE for JavaFX application built with gradle and launch4j

I'm trying to build a JavaFX exe using a pipeline on bitbucket with Gradle and the Launch4j plugin. It successfully builds, but when I download it and try to run the exe I get this error: java.lang.NoClassDefFoundError: javaFx/application/application.
I tried the build from IntelliJ using the same gradle file and it works Okay. I say Okay because in the launch4j folder there is the exe along with a lib Dir, which has the jar files. Ideally, would like all of the jar files in the exe (It doesn't run without the lib Dir). Anyhoo, with the build from the pipeline, it looks like it can't find the javafx jar. I did create another class called Launcher that doesn't extend Application but does call my main class, that does extend Application. I heard there were issues trying to import the JavaFx if it extends Application so I created another entry point into the application. With that said, here is most of my gradle file:
plugins {
id 'java'
id 'idea'
id "com.google.protobuf" version '0.8.19'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.24.1'
id 'checkstyle'
id 'pmd'
id 'edu.sc.seis.launch4j' version '2.5.3'
}
application {
mainModule = 'com.verlodesktopapplication'
mainClass = 'com.verlodesktopapplication.Launcher'
}
javafx {
version = '17.0.2'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.swing']
}
jlinkZip {
group = 'distribution'
}
jar {
manifest {
attributes(
'Main-Class': 'com.verlodesktopapplication.Launcher'
)
}
}
launch4j {
headerType="gui"
mainClassName='com.verlodesktopapplication.Launcher'
icon = "${projectDir}/icons/testicon.ico"
outfile="VDA.exe"
jreRuntimeBits="64"
jar="${buildDir}/libs/verlo-desktop-application-1.0.jar"
}
Here is what the manifest looks like:
Manifest-Version: 1.0
Main-Class: com.verlodesktopapplication.Launcher
Shouldn't the manifest include all of the jars? Any idea how to do that?

Set "Packaging" to POM file with Maven Gradle Plugin

I have an maven gradle plugin in my Android project, that generates the pom files (I only need the POM files, not to actually upload to artifactory).
I am generating an Android libraries (aar), so I need to add
<packaging>aar</packaging>
to the Pom file. However, the pom { } field does not have any "packaging" option. Any idea how to do it?
This is my current code:
task writePom {
doLast {
pom {
//packaging 'aar'
}.writeTo("$buildDir/pom.xml") } }

gradle war: how to build jar, not classes

Gradle war plugin: how to build a jar and add it to war?
projectRoot/
src/main/java
src/main/resources
src/main/webapp
build a jar (foo.jar) from the java source code and resources.
add the jar under the WEB-INF/lib of the war.
WEB-INF/lib/foo.jar
The war task will not build a jar by default, and add all java classes and resources under WEB-INF/classes.
UPDATE
The War plugin extends the Java plugin to add support for assembling web
application WAR files. It disables the default JAR archive generation of the
Java plugin and adds a default WAR archive task.
There is a way to enable the Jar generation and let task war depends on task jar?
not sure if eastwater still needs the answer, hope others with the same problem will find this helpful
you can add/configure the war task in build.gradle
war {
classpath = classpath - sourceSets.main.output
from (jar) {
into 'WEB-INF/lib'
}
}
once build succeed, in build/libs folder you'll see the generated jar and the war containing the generated jar instead of classes
Add those into your root build.gradle
plugins {
id 'java'
id 'idea'
}
jar{
String somestr=''
configurations.runtime.each{somestr=somestr+" lib\\"+it.name}
manifest{
attributes 'Main-Class':'your_class_name'
attributes 'Class-Path':somestr
}
}
task copyJar(type:Copy){
from configurations.runtime
into ('build/libs/lib')
}
task release(type: Copy,dependsOn:[build,copyJar]){
}
add finally run this command
gradle release

Why does my jar file not not contain any class files?

I'm trying to add a task (gen or gen2) to my build.gradle that does exactly the same as the Jar-task:
version = "0.0.1"
apply plugin: 'java'
task('gen', type: Jar) {
}
task gen2(type: Jar)
Running
gradle jar
generates a JAR-file that contains .class-files, while running
gradle gen
or
gradle gen2
generate a JAR-file that does NOT contain any .class-files.
Whats wrong with my class definition?
To build a jar with all the classes from main, as a default jar task would, do this:
task gen2(type: Jar){
baseName = 'gen2Jar'
from sourceSets.main.output
}
You can also do from(sourceSets.main.output){ include "package" } to customize what packages are included.
Alternatively, to copy settings from the default jar task:
task gen(type: Jar){
baseName = 'genJar'
with jar
}
Infact you can have both of these in the same build.gradle. Running gradle jar builds default jar. gradle gen builds genJar.jar and gradle gen2 builds gen2Jar.jar, all of which contain all the classes from java.main

Resources