-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradle Support/Example #14
Comments
We are planning to add Gradle support in the near future. |
please let me know what is wrong with that gradle build script? plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '4.0.2'
}
version '1.0.0'
group 'com.github.daggerok'
mainClassName = 'com.kumuluz.ee.EeApplication'
shadowJar.mustRunAfter jar
defaultTasks 'shadowJar'
repositories {
mavenCentral()
}
dependencies {
compile 'com.kumuluz.ee:kumuluzee-core:3.0.0'
compile 'com.kumuluz.ee:kumuluzee-servlet-jetty:3.0.0'
compile 'com.kumuluz.ee:kumuluzee-cdi-weld:3.0.0'
compile 'com.kumuluz.ee:kumuluzee-jax-rs-jersey:3.0.0'
compile 'com.kumuluz.ee:kumuluzee-json-p-jsonp:3.0.0'
} gradle shadowJar task can build uber jar file, but when I'm running it, I'm getting that error: # ...skipped
2018-11-21 22:24:14.345 INFO -- com.kumuluz.ee.jetty.JettyFactory -- Starting KumuluzEE on Jetty with 5 minimum and 100 maximum threads
2018-11-21 22:24:14.375 INFO -- com.kumuluz.ee.jetty.JettyFactory -- Starting KumuluzEE on port(s): 8080 [http/1.1]
2018-11-21 22:24:14.427 INFO -- com.kumuluz.ee.jetty.JettyServletServer -- Starting KumuluzEE with context root '/'
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Initializing components
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Found EE component CDI implemented by Weld
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.cdi.CdiComponent -- Initiating Weld
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Components initialized
2018-11-21 22:24:14.431 INFO -- com.kumuluz.ee.EeApplication -- Initializing extensions
2018-11-21 22:24:14.432 INFO -- com.kumuluz.ee.EeApplication -- Extensions Initialized
2018-11-21 22:24:14.433 INFO -- org.eclipse.jetty.server.Server -- jetty-9.4.z-SNAPSHOT; built: 2018-06-05T18:24:03.829Z; git: d5fc0523cfa96bfebfbda19606cad384d772f04c; jvm 1.8.0_192-b12
2018-11-21 22:24:14.507 WARNING -- org.eclipse.jetty.webapp.WebAppContext -- Failed startup of context o.e.j.w.WebAppContext@5ed828d{/,file:///private/var/folders/p9/kwk2r83x3hldqvc998h02qkw0000gp/T/kumuluzee-tmp-webapp299415749452541202/,STARTING}
java.lang.ExceptionInInitializerError
at org.eclipse.jetty.http.MimeTypes$Type.<init>(MimeTypes.java:103)
at org.eclipse.jetty.http.MimeTypes$Type.<clinit>(MimeTypes.java:58)
at org.eclipse.jetty.http.MimeTypes.<clinit>(MimeTypes.java:191)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:832)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:419)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:386)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.kumuluz.ee.jetty.JettyServletServer.startServer(JettyServletServer.java:81)
at com.kumuluz.ee.EeApplication.initialize(EeApplication.java:368)
at com.kumuluz.ee.EeApplication.<init>(EeApplication.java:73)
at com.kumuluz.ee.EeApplication.main(EeApplication.java:85)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
... 17 more seems like problem with what I'm trying to configure is this: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.daggerok</groupId>
<artifactId>kumuluzee-maven-gradle-app</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-bom</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-core</artifactId>
</dependency>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-servlet-jetty</artifactId>
</dependency>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-cdi-weld</artifactId>
</dependency>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-jax-rs-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-json-p-jsonp</artifactId>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>com.kumuluz.ee</groupId>
<artifactId>kumuluzee-maven-plugin</artifactId>
<version>${kumuluz.version}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> Thanks Regards, |
Hi! kumuluzee-maven-plugin packages Uber JAR in a custom way, among other things, it uses kumuluzee-loader to bootstrap application. If you want to replicate that behavior in Gradle I think your best option would be to observe Uber JAR created with Maven and try to replicate that with Gradle. |
Hi! Do you happen to have any further guidelines how to use kumuluzee maven build task with Gradle? Or a possible support for Gradle? |
@kustrun and I managed to get it working with Gradle, replicating the Uber JAR structure generated by maven plugin. Here's the minimal required configurations {
kumuluzeeLoader { transitive = false }
}
dependencies {
kumuluzeeLoader 'com.kumuluz.ee:kumuluzee-loader:3.1.0'
}
task repackageKumuluzee {
/*Unpack and copy kumuluzee loader*/
copy {
from zipTree(configurations.kumuluzeeLoader.singleFile).matching { include "**/*.class" }
into "$buildDir/classes/java/main"
outputs.upToDateWhen { false }
}
/*Create boot loader properties*/
file("$buildDir/classes/java/main/META-INF/kumuluzee").mkdirs()
file("$buildDir/classes/java/main/META-INF/kumuluzee/boot-loader.properties").text = "main-class=com.kumuluz.ee.EeApplication"
}
task buildKumuluzee {
jar {
baseName = "kumuluz-app"
archiveName = "${baseName}-${version}.${extension}"
manifest {
attributes "Main-Class": "com.kumuluz.ee.loader.EeBootLoader"
}
/*Copy project dependencies into lib folder as jars*/
into("lib") {
from configurations.runtimeClasspath
}
}
dependsOn repackageKumuluzee
finalizedBy build
} |
In order to run different main class you have to edit this boot-loader property: jar -> manifest -> attributes -> main-class property MUST NOT BE CHANGED! |
@ArtificialPB , @kustrun that's great. Would you be willing to contribute the complete Gradle build solution as a part of the kumuluzEE project? Much appreciated! |
@MBJuric Sure, should we make a PR with the above gradle build example added to the main repository readme file? https://github.com/kumuluz/kumuluzee |
@ArtificialPB Yes, please. Also, if you could provide a markdown page that we would include in our Wiki (similar to this one: https://github.com/kumuluz/kumuluzee/wiki/Uber-JAR-support) - "Gradle support". |
@MBJuric Please find the JAX-RS gradle sample in the following repository: https://github.com/ArtificialPB/kumuluzee-jax-rs-gradle And the Wiki page: https://gist.github.com/ArtificialPB/fa629f321fd3f9d74cc77078da4b4bab |
I've used this gradle file in order to build my uber jar. I'm getting this message: |
Thank you, @ArtificialPB I can confirm that I was able use your solution to build kumuluzee fat jar with gradle! It was little bit challenged migrate currect solution to Gradle Kotlin DSL, so I will left it here just in case if someone will be looking into it: val kumuluzeeLoader by configurations.creating {
extendsFrom(configurations["runtime"])
setTransitive(false)
}
val kumuluzeeVersion: String by project
dependencies {
kumuluzeeLoader("com.kumuluz.ee:kumuluzee-loader:$kumuluzeeVersion")
// dependencies
}
tasks {
register("kumuluzLoader", Copy::class.java) {
group = "KumuluzEE"
description = "Add KumuluzEE boot loader"
from(zipTree(configurations["kumuluzeeLoader"].singleFile).matching {
include("**/*.class")
})
into("$buildDir/classes/java/main")
outputs.upToDateWhen { false }
doLast {
val filename = "$buildDir/classes/java/main/META-INF/kumuluzee"
file(filename).mkdirs()
file("$filename/boot-loader.properties")
.writeText("main-class=com.kumuluz.ee.EeApplication\n", StandardCharsets.UTF_8)
}
}
register("kumuluzJar", Jar::class.java) {
group = "KumuluzEE"
description = "Build KumuluzEE uber (fat) jar"
archiveClassifier.set("all")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes("Main-Class" to "com.kumuluz.ee.loader.EeBootLoader")
}
from(configurations.runtimeClasspath.get()) {
into("lib") // dependencies
}
from(sourceSets.main.get().output) // app
shouldRunAfter("kumuluzLoader")
dependsOn("kumuluzLoader")
}
}
defaultTasks("kumuluzJar") Regards, |
Is there any roadmap to publish an gradle plugin? |
When using kumuluzee from Maven, there is a plugin that packages the application/jar in the right way.
There should also be a plugin for Gradle or at least a gradle sample project that shows how to package the jar in the correct way for kumuluzee.
Based on my first tries, it seems not to be as simple as a shaded jar where all kumuluzee jars are just shaded in the application-jar. When comparing the output of the maven build, it seems, that some select classes are in the main application-jar and the other dependencies are contains as Jars.
It would be good to have a gradle build example that sets this up in exactly the right way.
The text was updated successfully, but these errors were encountered: