enable preview features for gretty plugin - java

I'm trying to run Spring MVC app using gretty plugin for Gradle (JVM version is 14)
To deploy app I use tomcatRun task (tomcat version is 8.5.49).
If i use some preview feature (e.g. java.lang.String#formatted method) I have to add enable-preview flag to compileJava task:
compileJava {
options.compilerArgs += '--enable-preview'
}
However, if build.gradle contains such changes, something goes wrong and the following message appears in logs:
INFO: No Spring WebApplicationInitializer types detected on classpath
As a result all app endpoints aren't available.
In case of using jettyRun task the following exception is thrown:
17:14:38 WARN Failed startup of context o.a.g.JettyWebAppContext#2715644a
java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/config/ApplicationDispatcherServletInitializer (class file version 58.65535). Try running with '--enable-preview'
Is it possible to use preview features with gretty plugin?

Solved by adding --enable-preview to the list of JVM arguments in gretty configuration:
build.gradle
gretty {
jvmArgs = ['--enable-preview']
}
Checked on both Jetty(9.4.24.v20191120) and Tomcat(8.5.49)

Related

Gradle distributionUrl changes with 'ionic cordova run android' to older version, build failure

I've updated my Gradle distributionUrl to https://services.gradle.org/distributions/gradle-6.1.1-all.zip from gradle-4.1-all.zip, but when I run ionic cordova run android it reverts itself back to the 4.1-all.zip file. This happens around the time where the terminal comes to:
ANDROID_HOME=C:\Users\me\AppData\Local\Android\SDK
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
studio
Subproject Path: CordovaLib
Subproject Path: app
which then results in
FAILURE: Build failed with an exception.
*Where:
Build file 'C:\Users\me\Desktop\....\platforms\android\CordovaLib\build.gradle' line 40
* What went wrong:
A problem occurred evaluating project':CordovaLib'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.1.1. Current version is 4.1...
Line 40 in this case is apply plugin: 'com.android.library'
The issue I'm seeing is that the Gradle version is reverting itself back to the previous version. How can I get this to stay at version 6.1.1? Is there something wrong with the com.android.library plugin that I should be fixing?
my gradle dependencies are:
classpath 'com.andorid.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
my ionic info:
cli packages: (C:\Users\bg21562\AppData\Roaming\npm\node_modules)
#ionic/cli-utils : 1.19.3
ionic (Ionic CLI) : 3.20.1
global packages:
cordova (Cordova CLI) : 9.0.0 (cordova-lib#9.0.1)
local packages:
#ionic/app-scripts : 3.2.4
Cordova Platforms : android 7.1.4
Ionic Framework : ionic-angular 3.9.9
System:
Android SDK Tools : 26.1.1
Node : v8.11.3
npm : 6.11.3
OS : Windows 10
Environment Variables:
ANDROID_HOME : C:\Users\Bg21562\AppData\Local\Android\SDK
Misc:
backend : pro
Gradle versions are located in several locations, as it turns out.
In order to fix this, I found the distributionUrl as a variable in the following locations:
platforms\android\cordova\lib\builders\StudioBuilder.js and platforms\android\cordova\lib\builders\GradleBuilder.js
Both of these files include
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-4.1-all.zip';
which of course, needed to be replaced with 6.1.1-all.zip
Make sure to also replace the gradle-wrapper.properties file with the 6.1.1 gradle version.
I also found an option to add an export variable for CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL into the bash profile:
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=http\\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Best answers found here: Cordova build changes distributionUrl in gradle-wrapper.properties file

IntelliJ + Gradle + JavaFX building, but not running

I'm trying to run Gradle project with JavaFX in IntelliJ IDEA Ultimate on Windows. JavaFX was added in our latest Git push, before it was working.
I can build project without problems. I'm getting an errror while running main:
I have:
JDK 11.0.5 (the one from Oracle site, not openJDK), I'm using Java 11, all configured in IntelliJ
JDK installation directory (specifically /bin directory in it) added to my PATH
JAVA_HOME environment variable added with JDK installation directory
Project structure:
build.gradle (it was not built by me, I don't understand exactly what is written there and why):
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
group 'transportCompany'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.mongodb:mongodb-driver-sync:3.11.2'
compile group: 'org.openjfx', name: 'javafx', version: '11.0.2', ext: 'pom'
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
Main.java:
public class TransportCompanyApp extends Application {
private Stage primaryStage;
private MainAppPresenter presenter;
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("My first JavaFX app");
presenter = new MainAppPresenter(primaryStage);
this.presenter.initRootLayout();
//this.primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If I understand correctly, IntelliJ sees all files, there are no unresolved references in code, all imports work.
JavaFX jars are downloaded by Gradle:
They are configured as "Libraries", not "Global libraries", since they shouldn't be, with Gradle it should just be built, download everything and run, if I understand correctly.
I've tried creating new project with Git Checkout, it didn't work. Curiously though it worked for my colleagues (they have the same setup: JDK 11, Java 11, Windows; some even don't have JAVA_HOME at all and it works for them).
What I've tried:
JavaFX getting started
Error: JavaFX runtime components are missing, and are required to run this application with JDK 11
Error: JavaFX runtime components are missing - JavaFX 11 and OpenJDK 11 and Eclipse IDE
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000909940-Openjfx-11
https://openjfx-dev.openjdk.java.narkive.com/aFiw9uqi/error-javafx-runtime-components-are-missing-and-are-required-to-run-this-application
using JDK 13 and Java 13
changing project to modular
using JavaFX as Global Library and importing it to modules
What else can I do? I just want Gradle to download whatever I need and run this project. We've done that at university with JavaFX introduction with similar project and it did work on my current configuration (the only difference was that that one was with Maven).
EDIT
After running gradlew --info run I got:
> Task :run FAILED
Task ':run' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe''. Working directory:
C:\Users\Lenovo\Desktop\TO Command: C:\Program Files\Java\jdk-11.0.5\bin\java.exe --add-modules
javafx.controls,javafx.fxml --module-path C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\o
rg.openjfx\javafx-fxml\11.0.2\b3242e4c031558574de2a1da685bb5fcdbb8a530\javafx-fxml-11.0.2-win.j
ar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-controls\11.0.2\6c7637
07769c18adce406904c771c2ad1fcc370b\javafx-controls-11.0.2-win.jar;C:\Users\Lenovo\.gradle\cache
s\modules-2\files-2.1\org.openjfx\javafx-graphics\11.0.2\20459ea2cf714942bcbeb78a7f70ba3531dc1a
44\javafx-graphics-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjf
x\javafx-base\11.0.2\1852e57b8cf9a9b6488c33605bccd5d06ff210e1\javafx-base-11.0.2-win.jar -Dfile
.encoding=windows-1250 -Duser.country=PL -Duser.language=pl -Duser.variant -cp C:\Users\Lenovo\
Desktop\TO\build\classes\java\main;C:\Users\Lenovo\Desktop\TO\build\resources\main;C:\Users\Len
ovo\.gradle\caches\modules-2\files-2.1\org.mongodb\mongodb-driver-sync\3.11.2\a011ecee75c110e95
d33ece066f4bee149d5487a\mongodb-driver-sync-3.11.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2
\files-2.1\org.openjfx\javafx\11.0.2\6e90384c9fb4ec7ed8186c0e916c419c87a24cbf\javafx-11.0.2.pom
;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-fxml\11.0.2\b3242e4c0315
58574de2a1da685bb5fcdbb8a530\javafx-fxml-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-
2\files-2.1\org.openjfx\javafx-controls\11.0.2\6c763707769c18adce406904c771c2ad1fcc370b\javafx-
controls-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-c
ontrols\11.0.2\4ab633cf1eea60f76e2ae9905aedac862da88b08\javafx-controls-11.0.2.jar;C:\Users\Len
ovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-graphics\11.0.2\20459ea2cf714942bcbeb
78a7f70ba3531dc1a44\javafx-graphics-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\fil
es-2.1\org.openjfx\javafx-graphics\11.0.2\e522eb4ea422eceeee207b1c266ba3db19b2343a\javafx-graph
ics-11.0.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-base\11.0.
2\1852e57b8cf9a9b6488c33605bccd5d06ff210e1\javafx-base-11.0.2-win.jar;C:\Users\Lenovo\.gradle\c
aches\modules-2\files-2.1\org.openjfx\javafx-base\11.0.2\7fb2e4a8528ec9e434a9ac9ee98b39af79e6dc
b8\javafx-base-11.0.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.mongodb\mongod
b-driver-core\3.11.2\798e2d948326c5bfd9924e524bab22ee39c8f4f\mongodb-driver-core-3.11.2.jar;C:\
Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.mongodb\bson\3.11.2\96b17202f1250736ba83021
ff56550e83e8fd8c5\bson-3.11.2.jar TransportCompanyApp
Successfully started process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe''
Error: Could not find or load main class TransportCompanyApp
Caused by: java.lang.ClassNotFoundException: TransportCompanyApp
:run (Thread[Daemon worker,5,main]) completed. Took 0.367 secs.
FAILURE: Build failed with an exception.
The problem was solved. What I did:
Removed compile group: 'org.openjfx', name: 'javafx', version: '11.0.2', ext: 'pom' as dependency from gradle.build.
Changed mainClassName in gradle.build to mainClassName = "app.TransportCompanyApp".
Changed Run option in IntelliJ to use gradle run.

Jms dependency not resolved?

Hi I have created one docker-compose.yml file as bellow configuration
version: '3'
services:
activemq:
image: webcenter/activemq:latest
ports:
- 8161:8161
- 61616:61616
- 61613:61613
environment:
ACTIVEMQ_NAME: amq
ACTIVEMQ_REMOVE_DEFAULT_ACCOUNT: 'True'
ACTIVEMQ_ADMIN_LOGIN: admin
ACTIVEMQ_ADMIN_PASSWORD: admin
volumes:
- /container_data/activemq/data:/data/activemq
- /container_data/activemq/log:/var/log/activemq
I have gradle configuration as following:
task startDocker(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', 'docker-compose', '-f', './docker-compose.yml', 'up', '-d'
} else {
commandLine 'docker-compose', '-f', './docker-compose.yml', 'up', '-d'
}
}
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.jms.MyServer'
}
}
when i am running my java application independently it runs fine as
i am using configuration from following command:
docker container inspect <container-id>
but when i run jar file it's not able find classes of jms
following is an error i'm getting when i ran using jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/Destination
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
How could i run jar file and resolve this error ?
I'm guessing you have jms dependencies which are not packed inside your jar so it can't be run as a standalone.
If you want to pack your dependencies inside your jar you can use something like shadow or one-jar or its also not to difficult to hand roll your own solution.
Another option is to use the application plugin to create a zip or a tar containing
your jar
the dependency jars
a startup script

Build failure for JavaFX android app using the gluon mobile plugin

I just started a new gluon mobile multi view project with FXML and tried to run it before changing anything (apart from updating the jfxmobile-plugin version in the build.gradle file from 1.2.0 to 1.3.2). it works fine on desktop, but when i try to run the androidinstall gradle task (with my android phone connected) it fails. It gives me the following error:
:mergeClassesIntoJar
:shrinkMultiDexComponents
:createMainDexList
:writeInputListFile
[ant:java] Java Result: 1
:dex FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dex'.
> org.gradle.api.GradleException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.2.0'
}
jfxmobile {
downConfig {
version = '3.1.0'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
operating system: Windows 10.
Please let me know if any additional information is needed to determine the cause of the problem. Thank you.
gradlew --info android log:
http://pastebin.com/yNZbZcVk
Based on your log, I noticed you were using a 32 bits JDK on a 64 bits OS:
Starting process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_101\bin\java.exe''. Working directory: D:\Android_Projects\GluonMobile-MultiViewProjectwithFXML Command: C:\Program Files (x86)\Java\jdk1.8.0_101\bin\java.exe ...
By default, the jfxmobile plugin sets 2 GB for the JVM Xmx option on Android, and considering that on a 32 bits OS that won't be possible to allocate, the solution is setting a lower value.
Based on this line of code, you can set:
android {
dexOptions {
javaMaxHeapSize '1g'
}
}
Or maybe a little bit more (1.5g or so?).
Note that this will be solved if you use a 64 bits JDK. Make sure you update your JAVA_HOME environment variable accordingly, as you won't need to reduce the memory for your process.

cordova run android fails with com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

For the last few days I've been unable to run cordova run android (or rather, ionic run android) to test my Ionic app on my native device. When I run the command, I get the usual metric ton of output, along with 100% CPU usage from several Java Runtime processes, then the build finally fails with the stated in the title. The console shows this (truncated, as there's a ton of output):
:compileDebugNdk UP-TO-DATE :compileDebugSources
:transformClassesWithDexForDebug UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0,
0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:484)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) FAILED
BUILD FAILED
Total time: 1 mins 40.116 secs
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task :transformClassesWithDexForDebug.
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command
'C:\Program Files\Java\jdk1.8.0_73\bin\java.exe'' finished with
non-zero exit value 2
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Error: Error code 1 for command: cmd with args:
/s,/c,"E:\Documents\GitHub\app.auroras.live\platforms\android\gradlew
cdvBuildDebug -b
E:\Documents\GitHub\app.auroras.live\platforms\android\build.gradle
-PcdvBuildArch=arm -Dorg.gradle.daemon=true -Pandroid.useDeprecatedNdk=true"
I just went and updated any necessary tools and libraries in the Android SDK, then I removed and re-added the Android platform (cordova platform add android), making sure to check that all the relevant platform files were gone, and the project still fails to build.
EDIT: I also ran cordova clean, but that didn't work. It looks like the Google Play Services library is causing my app to hit the 64,000 method limit, but other than manually tweaking my gradle file (which I'm not au fait with yet), I'm not sure how I can shrink that down
EDIT 2: I tried tweaking my build.gradle file to remove the reference to "com.google.android.gms:play-services:+" (which I think is pushing my app above the 65535 method limit) but it just keeps coming back.
I also tried a build-extras.gradle to remove the dependency, but got another error. Ideally I'd like an answer that doesn't require constant re-working every time I want to build my app, but at this stage I'm keen for pretty much anything.
I did recently upgrade cordova, ionic and bower (using npm install -g cordova ionic bower after something went screwy with my %PATH% variable on Windows, but I wouldn't imagine that would break anything.
I'm running Windows 10, x64. java -version reports:
java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
Any suggestions?
:transformClassesWithDexForDebug UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0,
0xffff]: 65536
This message sounds like your project is too large.
You have too many methods. There can only be 65536 methods for dex.
Since the gradle plugin 0.14.0 and the Build Tools 21.1.0 you can use the multidex support.
Just add these lines in the build.gradle:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also in your Manifest add the MultiDexApplication class from the multidex support library to the application element
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
If you are using a own Application class, change the parent class from Application to MultiDexApplication.
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
For google play service:
Google Play services and DEX method limits
Resource Link:
Configuring Your App for Multidex with Gradle
Optimizing Multidex Development Builds
The routine builds performed as part of the development process with multidex typically take longer and can potentially slow your development process.
In order to mitigate the typically longer build times for multidex output, you should create two variations on your build output using the Android plugin for Gradle productFlavors: a development flavor and a production flavor.
The following build configuration sample demonstrates the how to set up these flavors in a Gradle build file:
android {
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
...
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Resource Link:
DexIndexOverflowException issue after updating to latest appcompat and support library
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Modifying build.gradle directly is not advisable as the changes will be overwritten after building android platform. Any extensions to build.gradle should be done by adding additional file like 'build-extras.gradle' as suggested in official documentation. As suggested by Grayda, the cleaner solution is to use the plugin which does the job like charm.
Came across one more cordova multiplex plugin which does the job and which is active. You can install the plugin using following command:
cordova plugin add https://github.com/solent/cordova-plugin-multidex
Posting the answer as it may benefit someone out there.
In addition to #SkyWalker's answer, I discovered a Cordova multidex plugin that is a lot "cleaner" (that is, no manual modification to your build.gradle files).
You simply install it with cordova plugin add --save https://github.com/jwall149/cordova-multidex and on next build, multidex will be enabled, which will resolve this issue.

Categories

Resources