I am using this "plugin" on javadoc to generate a UML Class Diagram with Gradle: https://github.com/talsma-ict/umldoclet
This "plugin" uses javadoc to create UML Class Diagrams.
I am working with the JavaFX library to build my application. When I run my custom task that should generate the image I get an error in my module-info.java that javafx.controls cannot be found.
build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
}
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
umlDoclet
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.18'
// Used for generating UML class diagram
umlDoclet "nl.talsmasoftware:umldoclet:2.0.6"
}
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
task generateUmlClass(type: Javadoc) {
dependsOn("javadoc")
source = sourceSets.main.allJava
destinationDir = reporting.file("uml")
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
mainClassName = "$moduleName/nl.avans.sagrada.MainApp"
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'Sagrada'
}
}
I tried adding dependsOn("javadoc") so I would build first but this doesn't seem to work.
My module-info.java
module Sagrada {
requires javafx.controls;
requires java.sql;
opens nl.avans.sagrada to javafx.base;
opens nl.avans.sagrada.controllers to javafx.controls;
opens nl.avans.sagrada.view.scenes to javafx.controls;
opens nl.avans.sagrada.view.panes to javafx.controls;
opens nl.avans.sagrada.database to java.sql;
exports nl.avans.sagrada;
exports nl.avans.sagrada.controllers;
exports nl.avans.sagrada.view.scenes;
exports nl.avans.sagrada.view.panes;
exports nl.avans.sagrada.interfaces;
exports nl.avans.sagrada.helpers;
exports nl.avans.sagrada.models;
exports nl.avans.sagrada.database;
exports nl.avans.sagrada.database.annotations;
exports nl.avans.sagrada.database.models;
}
Whenever I try to run gradle generateUmlClass it gives following error:
2:55:13 PM: Executing task 'generateUmlClass'...
> Configure project :
Found module name 'Sagrada'
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar
> Task :startScripts
> Task :distTar
> Task :distZip
> Task :assemble
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :build
> Task :generateUmlClass FAILED
D:\Avans\Blok 2\Sagrada-Core\src\main\java\module-info.java:2: error: module not found: javafx.controls
requires javafx.controls;
^
D:\Avans\Blok 2\Sagrada-Core\src\main\java\module-info.java:3: error: module not found: javafx.fxml
requires javafx.fxml;
^
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateUmlClass'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): 'D:\Avans\Blok 2\Sagrada-Core\build\tmp\generateUmlClass\javadoc.options'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
7 actionable tasks: 5 executed, 2 up-to-date
2:55:15 PM: Task execution finished 'generateUmlClass'.
For starters, you are adding two javadoc tasks:
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
task generateUmlClass(type: Javadoc) {
dependsOn("javadoc")
source = sourceSets.main.allJava
destinationDir = reporting.file("uml")
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
With same options in both and when you run ./gradlew generateUmlClass you are calling both tasks.
If you add some required options to one of them, the other will miss it. So you should only use one. Let's keep the default task javadoc.
Now:
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
destinationDir = reporting.file("uml")
}
If you run ./gradlew javadoc, you get the errors you have reported:
...src/main/java/module-info.java:2: error: module not found: javafx.controls
requires javafx.controls;
^
This happens because JavaFX is modular, and you should put it in the module-path.
The JavaFX gradle org.openjfx.javafxplugin plugin does precisely that for the run task, but not for the Javadoc one, so to fix the issue we need to add an option to the task with the module-path.
Using gradle's addStringOption, the way to do it is:
javadoc {
options.addStringOption('-module-path', ...)
...
}
The module path now can be taken from the classpath (classpath.asPath), however the JavaFX plugin uses implementation instead of the deprecated compile, so the now we need to use runtimeClasspath:
javadoc {
options.addStringOption('-module-path', configurations.runtimeClasspath.asPath)
...
}
Finally, this is all you should need:
javadoc {
options.addStringOption('-module-path', configurations.runtimeClasspath.asPath)
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
destinationDir = reporting.file("uml")
}
Now running ./gradlew javadoc should work successfully.
At least I can get some nice SVG images under `build/reports/uml:
Please let me provide some background to this question which seems resolved already.
I am the author of UMLDoclet; it is a Javadoc Doclet, which is indeed kind of a plugin to the Javadoc tool.
It works as follows:
Call the Standard Doclet from your Javadoc version to generate the regular HTML documentation.
Generate the following PlantUML diagrams:
Class diagram for each documented class
Package diagram for each documented package
Package dependency diagram with a dependency graph containing all documented packages (This was the diagram you shared, it contains many dependency cycles by the way)
Postprocess the generated HTML documents to embed the class, package and dependency diagrams where possible.
Because the doclet uses PlantUML, you have to have Graphviz installed locally when generating the diagrams.
By the way; I would have appreciated it a lot if you had included a link to this Stackoverflow post in the issue you filed in my github repo.
I'm glad your issue was resolved and I'd like to thank José Pereda for his elaborate answer!
Related
I have a project working with gradle and everything build and run perfectly but I have issues packaging my application. I work on WSL and would like to have both linux and windows executables but to begin having one is okay I don't really care as long as it works and I can understand how to replicate it on the other OS.
So far, I have read a lot of things on the internet and tried to use this plugin in order to package my application. But when I use gradle jlink, I am warned about a duplicate module issue as you can see below. I have tried many things but cannot find anythign which works or a similar problem on the web. Would you have any clue on what I may be overlooking because of my inexperience?
Thank you in advance !
Starting a Gradle Daemon, 31 busy and 1 incompatible and 12 stopped Daemons could not be reused, use --status for details
> Configure project :
Project : => 'CharacterCreator' Java module
> Task :createMergedModule
error: duplicate module on application module path
module in javafx.base
error: duplicate module on application module path
module in javafx.controls
2 errors
> Task :createMergedModule FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':createMergedModule'.
> Process 'command '/opt/graalvm-svm-java11-linux-gluon-22.1.0.1-Final/bin/javac'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 42m 15s
5 actionable tasks: 3 executed, 2 up-to-date
Here is my gradle.build file :
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.16.2'
}
repositories {
mavenCentral()
mavenLocal()
}
javafx {
version = "19"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
implementation "org.aerofx:aerofx:0.2"
implementation "pdfbox:pdfbox:0.7.3"
implementation "org.javatuples:javatuples:1.2"
implementation "org.controlsfx:controlsfx:11.0.3"
implementation "org.mariadb.jdbc:mariadb-java-client:2.1.2"
implementation "io.gitlab.vincent-lambert:miscellaneousWidgets:1.7"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "org.apache.httpcomponents:httpmime:4.3.1"
}
application {
mainModule = 'CharacterCreator'
mainClass = 'CharacterCreator.Menu.App'
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher{
name = 'hello'
jvmArgs = ['-Dlog4j.configurationFile=./log4j2.xml']
}
}
And my module-info file :
module CharacterCreator {
requires aerofx;
requires javafx.fxml;
requires pdfbox;
requires javatuples;
requires java.sql;
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires org.controlsfx.controls;
requires mariadb.java.client;
requires miscellaneousWidgets;
requires java.desktop;
requires java.net.http;
requires httpmime;
opens CharacterCreator.Creator to javafx.fxml;
exports CharacterCreator.Creator;
opens CharacterCreator.Edits to javafx.fxml;
exports CharacterCreator.Edits;
opens CharacterCreator.Menu to javafx.fxml;
exports CharacterCreator.Menu;
opens CharacterCreator.Misc to javafx.fxml;
exports CharacterCreator.Misc;
opens CharacterCreator.Races to javafx.fxml;
exports CharacterCreator.Races;
opens CharacterCreator.Relations to javafx.fxml;
exports CharacterCreator.Relations;
opens CharacterCreator.Visus to javafx.fxml;
exports CharacterCreator.Visus;
}
I had the same problem, and I found out, that the folder build/jlinkbase/jlinkjars contained mentioned modules for both platform - mac (which I use to develop) and win.
after reading https://github.com/openjfx/javafx-gradle-plugin/issues/65 I just needed to identify the "polluting" library and applied the fix, which was mentioned:
implementation (....) { exclude group:org.openjfx }
I'm using Gradle (4.10.3, but I've tried most versions up through 5.4.1) with JDK 12.0.1 and the org.beryx.jlink plugin (2.10.4), but am running into this error every time I attempt to create the jlink image:
-> Task :createMergedModule
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper$2.run().
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper.secureGetServiceLoader().
Cannot derive uses clause from service loader invocation in:
org/apache/commons/compress/utils/ServiceLoaderIterator.().
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:393:
error: the service implementation does not have a default constructor:
XBeansXPath
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with
org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394:
error: the service implementation does not have a default constructor:
XBeansXQuery
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with
org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
2 errors
-> Task :createMergedModule FAILED
When I click through to the lines throwing the errors in the merged module-info.java, it points to these two:
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
My build.gradle file looks like this:
plugins {
id 'application'
id 'idea'
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'org.beryx.jlink' version '2.10.4'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-csv:1.6'
compile 'org.apache.poi:poi-ooxml:4.1.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.5.0-M1'
}
// ### Application plugin settings
application {
mainClassName = "$moduleName/path.to.myapp"
}
// ### Idea plugin settings
idea {
module {
outputDir = file("out/production/classes")
}
}
// ### Java plugin settings
sourceCompatibility = JavaVersion.VERSION_11
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
test {
useJUnitPlatform()
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}
// ### JavaFX plugin settings
javafx {
version = "12.0.1"
modules = ['javafx.controls', 'javafx.fxml']
}
// ### jlink plugin settings
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
Any ideas on how I can address this?
The following possible solution is based just on your build file, without knowing about your module-info or the project's code, so it might not work.
It is also based on this issue at the jlink plugin's repository.
First, let me explain how this plugin works: since the (JDK) jlink tool doesn't allow non-modular dependencies, the plugin will try to collect all of them and create on the fly a module, that can be added to the module-path. This module is named $yourModuleName.mergedModule.
Now I'm adding your dependencies to a simple JavaFX project. When I run ./gradlew jlink I get the same errors you have posted. If you check the errors:
myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394: error
This shows that the created module is named myapp.merged.module, and that it has a module-info descriptor. If you open it you will see all the exports (the module will export every package of the dependencies by default), the requires and the provides:
open module myapp.merged.module {
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
requires java.xml.crypto;
requires java.logging;
requires java.sql;
requires java.xml;
requires java.desktop;
requires java.security.jgss;
requires jdk.javadoc;
uses java.nio.file.spi.FileSystemProvider;
provides com.fasterxml.jackson.core.JsonFactory with com.fasterxml.jackson.core.JsonFactory;
provides com.fasterxml.jackson.core.ObjectCodec with com.fasterxml.jackson.databind.ObjectMapper;
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
}
So now the question is: should you add some more requirements to your own module? The answer is explained here: that will increase unnecessary your project's size. A better way is to use the mergedModule script block:
The mergedModule block allows you to configure the module descriptor of the merged module
And:
the module descriptor is created using the algorithm implemented by the suggestMergedModuleInfo task.
If you run ./gradlew suggestMergedModuleInfo you will basically get the same contents for the merged module descriptor as above.
A possible solution is to start just adding some requires to the merged module descriptor, and try again.
I started with:
jlink {
mergedModule {
requires "java.xml"
}
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
and I could run ./gradlew jlink successfully.
If you check the merged module descriptor now, it will look like:
open module myapp.merged.module {
requires java.xml;
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
}
containing only the explicit requires, all the exports, but without provides, so the errors will be gone.
Since I don't have your code, I can't say if this will work for you, but it did for me with the same dependencies.
I created a java 10 project with intelliJ, using gradle.
I copied some stuff into it (some "AppFx" class using the library guava and javaFx, and a personal build.gradle file).
I also added a module-info.java file in src/main/java with this content:
module biblio5.main {
requires javafx.graphics;
requires javafx.controls;
requires javafx.base;
requires guava;
}
in which grava is an automatic module.
here is the relevant part of build.gradle:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
intelliJ can compile the project (using the hammer-like icon) but when I run the compileJava gradle task from intelliJ, I get an error:
13:12:46: Executing task 'compileJava'...
Task :compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5:
error: module not found: guava
requires guava;
^ 1 error
I spent a lot of time on the net but did not manage to find an answer.
thank you
ps: here is the entire build.gradle:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
}
repositories {
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
jcenter()
}
}
plugins {
id 'java'
id 'application'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'eu.appsatori.fatjar'
group 'lorry'
version '1'
sourceCompatibility = 1.10
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
//********************************************************************************************
launch4j {
outfile='bibliotek-v3.exe'
mainClassName = 'lorry.AppFx'
icon = "${projectDir}\\icons\\hands2.ico"
copyConfigurable = project.tasks.fatJar.outputs.files
//jar = "lib/${project.tasks.fatJar.archiveName}"
//headerType = "console"
jar = "${buildDir}\\productFatJar\\fat.jar"
}
jar {
baseName = 'executable3'
version = ''
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task copyExecutable(type: Copy) {
from file("${buildDir}\\launch4j\\bibliotek-v3.exe")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyJar(type: Copy) {
from file("${buildDir}\\jfx\\app\\bibliotek-v3.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyFatJar(type: Copy) {
from file("${buildDir}\\productFatJar\\fat.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
createExe.doLast{
tasks.copyExecutable.execute()
}
task createJar(){
doLast{
tasks.jfxJar.execute()
tasks.jfxNative.execute()
tasks.copyJar.execute()
}
}
jfx {
jfxMainAppJarName = "bibliotek-v3.jar"
// minimal requirement for jfxJar-task
mainClass = 'lorry.AppFx'
// minimal requirement for jfxNative-task
vendor = 'lolveley'
}
fatJar {
destinationDir=file("${buildDir}\\productFatJar")
archiveName="fat.jar"
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task createFats(){
doLast{
tasks.fatJar.execute()
tasks.copyFatJar.execute()
tasks.createExe.execute()
}
}
EDIT
well, I made the change, and now I have "com.google.commons" instead guava in module-info.java, but I still get this error:
Testing started at 14:20 ... 14:20:14: Executing task 'check'...
Task :compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5:
error: module not found: com.google.common
requires com.google.common;
^ 1 error
I changed gradle in intelliJ (the default option - recommended - was "default gradle wrapper") to my local gradle (v4.9), but without any effect.
What do you mean by "compatible with java"? What about try with a java 9 installation?
Update: Gradle 6.4 added basic support for Jigsaw modules. See this sample in the documentation (which also links to other related documentation). Note that the Building Java 9 Modules article linked to in this answer has changed significantly since this answer was posted.
The issue is Gradle still (as of 4.10-rc-2) doesn't have first-class support for Jigsaw modules. All the tasks will use the classpath, not the modulepath, when executing. This obviously will cause issues when trying to create a modular library/application (with module-info.java).
If you want to use Jigsaw modules in your project you should read Building Java 9 Modules. Your scenario, as #nullpointer mentions, is best covered by this section of the linked document. The takeaway is to add the following to your build.gradle file:
ext.moduleName = 'your.module'
compileJava {
inputs.property('moduleName', moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath
]
classpath = files()
}
}
They also have sections for modifying the compileTestJava task (here) and the test task (here). Personally, I tend to not modify those tasks as testing often requires a lot of reflection which in turn requires a lot of --add-opens arguments. If you find out that's not true (haven't tried it in a while) or there's a better way, please let me know.
If your Gradle project is an application you also want to read the section covering the run and assemble tasks.
There is an experimental Gradle plugin that does all this for you: experimental-jigsaw. The plugin is limited, however, and there is a fork on GitHub, named chainsaw, that adds more features. Note: I don't know how maintained either plugin is.
Another Gradle plugin is available: Gradle Modules Plugin.
If you want to watch for updates regarding Jigsaw support in Gradle they maintain an epic on GitHub.
Also, to include what #nullpointer commented, you should be using a version of Guava that includes an Automatic-Module-Name entry in its manifest. Without this entry (combined with no module-info) the name of the module is subject to the name of the jar file; which may change unexpectedly. In other words, the Automatic-Module-Name entry makes for a better contract regarding the name of an automatic module. The first version that Guava added this entry is 23.2:
Changelog
Added JPMS module name com.google.common for Guava.
...
However, the most recent version (as of writing this answer) is 26.0.
More information about automatic modules can be found:
in the Javadoc of ModuleFinder.of(Path...)
this section of The State of the Module System
and this Stack Overflow question
I am using gradle shadow plugin to build my uber jar.
build.grade file looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
compile "com.amazonaws:aws-lambda-java-events:1.3.0"
}
assemble.dependsOn(shadowJar)
It produces following jars in build/libs folder.
myProject-1.0.0-SNAPSHOT.jar
myProject-1.0.0-SNAPSHOT-all.jar '//uber jar
I want to replace original jar with uber jar. How do i do this?
It isn't clear why want to do this, but I'm assuming you mean "with the original JAR's name". You should do 2 things:
Give a different classifer to the jar task (or archiveName, or the other properties that affect the name) or disable it so that you don't constantly overwrite it on every build and avoid doing unnecessary work
Change the classifier on the shadowJar task
The ShadowJar extends from the Gradle built-in Jar task, so most of the configuration options from that apply to the ShadowJar task.
tasks.jar.configure {
classifier = 'default'
}
tasks.shadowJar.configure {
classifier = null
}
For least keystrokes, without burning any bridges,
replace the line:
assemble.dependsOn(shadowJar)
with:
jar {
enabled = false
dependsOn(shadowJar { classifier = null })
}
Verify:
$ gradle assemble --console=plain
:compileJava
:processResources NO-SOURCE
:classes
:shadowJar
:jar SKIPPED
:assemble UP-TO-DATE
Perhaps disabling the jar task in build.gradle will work
apply plugin: 'java'
jar.enabled = false
So you will only have your uber jar.
You can do it in that way :
// save the old jar task
def oldJarTask = tasks.jar
// remove the original jar tasks from the tasks list
tasks.remove(jar)
// create a new task named "jar" thats depends on shadowJar
// when you will run jar task it will be actually run the shadow jar
task jar(dependsOn:[shadowJar])
// create a task to run the plain old good jar task from gradle :)
task oldJar(dependsOn: oldJarTask)
This was tested and worked, hoped it helped you!
I am trying to upgrade my game to libGDX 1.9.5. The game works fine on desktop, but when I try to build the HTML version I get the following error:
Configuration on demand is an incubating feature.
:core:compileJava UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:html:compileJava UP-TO-DATE
:html:processResources UP-TO-DATE
:html:classes UP-TO-DATE
:html:addSource
:html:compileGwt
Loading inherited module 'tech.otter.merchant.GdxDefinition'
Loading inherited module 'com.badlogic.gdx.backends.gdx_backends_gwt'
Loading inherited module 'com.google.gwt.user.User'
Loading inherited module 'com.google.gwt.media.Media'
Loading inherited module 'com.google.gwt.user.UI'
Loading inherited module 'com.google.gwt.uibinder.UiBinder'
[ERROR] Line 20: Unexpected element 'resource'
[ERROR] Failure while parsing XML
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.util.xml.DefaultSchema.onUnexpectedElement(DefaultSchema.java:86)
Historically, the biggest challenges for me when using GWT have been VisUI and gdx-kiwi, but I have gone to their wikis and updated their versions in my gradle files shown below:
/build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath "com.badlogicgames.gdx:gdx-tools:1.9.4"
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.1'
ext {
appName = "merchant"
gdxVersion = '1.9.5'
roboVMVersion = '2.2.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
kiwiVersion = '1.8.1.9.4'
visVersion = '1.3.0-SNAPSHOT'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile "com.github.czyzby:gdx-kiwi:$kiwiVersion"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion:sources"
compile "com.github.czyzby:gdx-kiwi:$kiwiVersion:sources"
compile "com.kotcrab.vis:vis-ui:$visVersion:sources"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.github.czyzby:gdx-kiwi:$kiwiVersion"
compile "com.kotcrab.vis:vis-ui:$visVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
html/build.gradle
apply plugin: "java"
apply plugin: "jetty"
gwt {
gwtVersion='2.6.1' // Should match the gwt version used for building the gwt backend
maxHeapSize="1G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY
minHeapSize="1G"
src = files(file("src/")) // Needs to be in front of "modules" below.
modules 'tech.otter.merchant.GdxDefinition'
devModules 'tech.otter.merchant.GdxDefinitionSuperdev'
project.webAppDirName = 'webapp'
compiler {
strict = true;
enableClosureCompiler = true;
disableCastChecking = true;
}
}
task draftRun(type: JettyRunWar) {
dependsOn draftWar
dependsOn.remove('war')
webApp=draftWar.archivePath
daemon=true
}
task superDev(type: de.richsource.gradle.plugins.gwt.GwtSuperDev) {
dependsOn draftRun
doFirst {
gwt.modules = gwt.devModules
}
}
task dist(dependsOn: [clean, compileGwt]) {
doLast {
file("build/dist").mkdirs()
copy {
from "build/gwt/out"
into "build/dist"
}
copy {
from "webapp"
into "build/dist"
}
copy {
from "war"
into "build/dist"
}
delete "../../madigan.github.io/merchant/"
copy {
from "build/dist"
into "../../madigan.github.io/merchant/"
}
doGit
}
}
task doGit(type: Exec) {
commandLine 'git', '-C', '../../madigan.github.io', 'add', '.'
commandLine 'git', '-C', '../../madigan.github.io', 'commit', '-m', '"Distribution."'
commandLine 'git', '-C', '../../madigan.github.io', 'push'
}
draftWar {
from "war"
}
task addSource << {
sourceSets.main.compileClasspath += files(project(':core').sourceSets.main.allJava.srcDirs)
}
tasks.compileGwt.dependsOn(addSource)
tasks.draftCompileGwt.dependsOn(addSource)
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-html"
}
Any advice or tips on how to troubleshoot this error would be much appreciated.
[EDIT]
I read the release notes a little closer, and it says that I should change the GWT version to 2.8.0. Even when I do this, I still get the following error:
Configuration on demand is an incubating feature.
:core:compileJava UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:html:compileJava UP-TO-DATE
:html:processResources UP-TO-DATE
:html:classes UP-TO-DATE
:html:addSource
:html:compileGwt
Unknown argument: -XenableClosureCompiler
Google Web Toolkit 2.8.0
Compiler [-logLevel (ERROR|WARN|INFO|TRACE|DEBUG|SPAM|ALL)] [-workDir dir] [-X[no]closureFormattedOutput] [-[no]compileReport] [-X[no]checkCasts] [-X[no]classMetadata] [-[no]draftCompile] [-[no]checkAssertions] [-XfragmentCount numFragments] [-XfragmentMerge numFragments] [-gen dir] [-[no]generateJsInteropExports] [-XmethodNameDisplayMode (NONE|ONLY_METHOD_NAME|ABBREVIATED|FULL)] [-Xnamespace (NONE|PACKAGE)] [-optimize level] [-[no]saveSource] [-setProperty name=value,value...] [-style (DETAILED|OBFUSCATED|PRETTY)] [-[no]failOnError] [-[no]validateOnly] [-sourceLevel [auto, 1.8]] [-localWorkers count] [-[no]incremental] [-war dir] [-deploy dir] [-extra dir] [-saveSourceOutput dir] module[s]
where
-logLevel The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM or ALL (defaults to INFO)
-workDir The compiler's working directory for internal use (must be writeable; defaults to a system temp dir)
-X[no]closureFormattedOutput EXPERIMENTAL: Enables Javascript output suitable for post-compilation by Closure Compiler (defaults to OFF)
-[no]compileReport Compile a report that tells the "Story of Your Compile". (defaults to OFF)
-X[no]checkCasts EXPERIMENTAL: DEPRECATED: use jre.checks.checkLevel instead. (defaults to OFF)
-X[no]classMetadata EXPERIMENTAL: Include metadata for some java.lang.Class methods (e.g. getName()). (defaults to ON)
-[no]draftCompile Compile quickly with minimal optimizations. (defaults to OFF)
-[no]checkAssertions Include assert statements in compiled output. (defaults to OFF)
-XfragmentCount EXPERIMENTAL: Limits of number of fragments using a code splitter that merges split points.
-XfragmentMerge DEPRECATED (use -XfragmentCount instead): Enables Fragment merging code splitter.
-gen Debugging: causes normally-transient generated types to be saved in the specified directory
-[no]generateJsInteropExports Generate exports for JsInterop purposes (defaults to OFF)
-XmethodNameDisplayMode EXPERIMENTAL: Specifies method display name mode for chrome devtools: NONE, ONLY_METHOD_NAME, ABBREVIATED or FULL (defaults to NONE)
-Xnamespace Puts most JavaScript globals into namespaces. Default: PACKAGE for -draftCompile, otherwise NONE
-optimize Sets the optimization level used by the compiler. 0=none 9=maximum.
-[no]saveSource Enables saving source code needed by debuggers. Also see -debugDir. (defaults to OFF)
-setProperty Set the values of a property in the form of propertyName=value1[,value2...].
-style Script output style: DETAILED, OBFUSCATED or PRETTY (defaults to OBFUSCATED)
-[no]failOnError Fail compilation if any input file contains an error. (defaults to ON)
-[no]validateOnly Validate all source code, but do not compile. (defaults to OFF)
-sourceLevel Specifies Java source level (defaults to 1.8)
-localWorkers The number of local workers to use when compiling permutations
-[no]incremental Compiles faster by reusing data from the previous compile. (defaults to OFF)
-war The directory into which deployable output files will be written (defaults to 'war')
-deploy The directory into which deployable but not servable output files will be written (defaults to 'WEB-INF/deploy' under the -war directory/jar, and may be the same as the -extra directory/jar)
-extra The directory into which extra files, not intended for deployment, will be written
-saveSourceOutput Overrides where source files useful to debuggers will be written. Default: saved with extras.
and
module[s] Specifies the name(s) of the module(s) to compile
:html:compileGwt FAILED
[EDIT #2]
Now that the flag is removed per #Colin Altworth's answer, I get the following error particular to vis-ui (again, updated to use the recommended version for libGDX 1.9.5):
:html:compileGwt
Compiling module tech.otter.merchant.GdxDefinition
Tracing compile failure path for type 'com.kotcrab.vis.ui.util.async.AsyncTask'
[ERROR] Errors in 'jar:file:/home/john/.gradle/caches/modules-2/files-2.1/com.kotcrab.vis/vis-ui/1.3.0-SNAPSHOT/e5f8abbdc3524212158f65d63c9a28d226795f97/vis-ui-1.3.0-SNAPSHOT-sources.jar!/com/kotcrab/vis/ui/util/async/AsyncTask.java'
[ERROR] Line 46: The constructor Thread(new Runnable(){}, String) is undefined
[ERROR] Line 51: The method start() is undefined for the type Thread
[ERROR] Aborting compile due to errors in some input files
:html:compileGwt FAILED
FAILURE: Build failed with an exception.
[EDIT #3]
Turns out the rest of the issue was a bug in VisUI- the latest update tries to use the Thread class, which is not supported by GWT.
Unknown argument: -XenableClosureCompiler
Remove the closure flag from your gradle GWT build:
gwt {
gwtVersion='2.6.1' // Should match the gwt version used for building the gwt backend
maxHeapSize="1G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY
minHeapSize="1G"
src = files(file("src/")) // Needs to be in front of "modules" below.
modules 'tech.otter.merchant.GdxDefinition'
devModules 'tech.otter.merchant.GdxDefinitionSuperdev'
project.webAppDirName = 'webapp'
compiler {
strict = true;
enableClosureCompiler = true;//<------------------------REMOVE THIS
disableCastChecking = true;
}
}
GWT no longer supports this experimental flag.
Html module of libGDX version 1.9.5 depends on gwtVersion 2.8.0 and this version no longer supports this flag so remove this flag.