ssl certificate issue for jgit in javafx app image versus javafx app runtime - ssl

I have developed a simple JavaFX app using jgit, that is allowing users to play with git.
When the app was started from the IntelliJ idea, I was able to clone the GitHub repo using my jgit implementation of the "git clone" command without any issues. But as soon as I created an image from my app and started the app from the image, I am getting an SSL certificate issue:
Exception:org.eclipse.jgit.api.errors.TransportException:
Secure connection to https://my-github-repo.git could not be established because of SSL problems.
I am trying to understand why I am getting the SSL certificate issue only when I am running the app from the image. Can somebody explain that? I understand that I can disable SSL verification (there are some questions answered on that topic), but I want to know why it is working from IDE and not from the created image...
here is my simplified git clone implementation for http:
try {
CloneCommand command = Git.cloneRepository();
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(httpUsername, httpPassword));
// run the clone command
command.setURI(repositoryUrl);
command.setDirectory(dirFramework);
git = command.call();
} catch (Exception e) {
LOG.error("Error occurred during task: Git clone: " + e);
}
For creating the image I am using the "org.beryx.runtime" plugin with the Gradle task "runtime".
Here is the build.gradle content:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.runtime' version '1.11.4'
}
group 'org.sovap'
version '1.0-SNAPSHOT'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
// xml stuff
compile 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
compile 'org.glassfish.jaxb:jaxb-runtime:2.3.2'
compile 'jakarta.activation:jakarta.activation-api:1.2.2'
// logger
compile 'org.apache.logging.log4j:log4j-core:2.13.3'
compile 'org.slf4j:slf4j-api:1.7.30'
compile 'org.slf4j:slf4j-simple:1.7.30'
// cucumber
compile 'io.cucumber:gherkin:15.0.2'
// jgit
compile 'org.eclipse.jgit:org.eclipse.jgit:5.9.0.202009080501-r'
compile 'org.eclipse.jgit:org.eclipse.jgit.archive:5.9.0.202009080501-r'
compile 'org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:5.9.0.202009080501-r'
// file utils
compile 'commons-io:commons-io:2.7'
//controlsfx
compile 'org.controlsfx:controlsfx:11.0.2'
}
javafx {
version = "15"
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', "javafx.graphics"]
}
application {
mainClassName = 'org.sovap.taman.Launcher'
applicationName = 'taman'
}
runtime {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
imageDir = file("$buildDir/taman")
}
Edit 1:
How the image is created? - image is created with the plugin 'org.beryx.runtime' version '1.11.4', with Gradle task called 'runtime'. At the end of the build.gradle content you can see some specific configuration for runtime task.
Also, it is possible to include modules there as described here: https://badass-runtime-plugin.beryx.org/releases/latest/
I have tested the config with modules you are mentioning for runtime task in build.gradle (also one by one):
runtime {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
imageDir = file("$buildDir/taman")
modules = ['jdk.crypto.cryptoki', 'jdk.crypto.ec', 'jdk.crypto.mscapi']
}
But with that I am getting following exception when starting the app from image:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
at org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory.newConfigurationBuilder(ConfigurationBuilderFactory.java:38)
at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.<init>(PropertiesConfigurationBuilder.java:72)
at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:52)
at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
at org.sovap.taman.App.<clinit>(App.java:15)
at org.sovap.taman.Launcher.main(Launcher.java:6)
Caused by: java.lang.ClassNotFoundException: javax.xml.stream.XMLStreamException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
What version of Java 11 are you using? - java version "11.0.8" 2020-07-14 LTS
Regarding the different versions of JDK for image and for IntelliJ IDEA environment - it should be using the same installation on my machine
I guess I need to add modules to the runtime task, but I do not know which ones and how to identify them... Any direction you can point me to?
Edit 2:
According to the accepted answer, I was missing modules in my runtime task configuration. Here is how I have figured which ones to add:
The plugin 'org.beryx.runtime' contains a task I used for suggesting modules for the runtime task (task: suggestModules)
After running it I have created a list of modules with the following runtime config (included the ones from accepted answer):
runtime {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
imageDir = file("$buildDir/taman")
modules = [
'java.desktop',
'java.logging',
'java.xml',
'java.compiler',
'java.datatransfer',
'java.rmi',
'java.sql',
'java.naming',
'java.scripting',
'java.management',
'java.security.jgss',
'jdk.jfr',
'java.net.http',
'jdk.jsobject',
'jdk.xml.dom',
'jdk.unsupported',
'jdk.crypto.cryptoki',
'jdk.crypto.ec',
'jdk.crypto.mscapi']
}
Now everything works as expected.

The most likely situation is that you are missing a module in the JRE image related to crypto that is required to authenticate the SSL connection.
What jdk.crypto.* modules are in the final image?
Perhaps if one of these is missing it will affect the ability to handle the SSL certificates?
jdk.crypto.cryptoki
jdk.crypto.ec
jdk.crypto.mscapi
Since some aspects of the security/crypto code are done via service providers, perhaps when you generate the JRE image you should pass the
"--bind-services" option to "Link in service provider modules and their dependences"
You will need to share more details about how the image is created and what specific errors are reported. Try to include the full stack trace of any reported exceptions.
What version of Java 11 are you using?
Could you be running into this: JDK 11 SSL Error on valid certificate (working in previous versions)
(It is unlikely if you are running with the same JDK version in the IDE and the packaged image, but thought I would mention it just in case it gives you a hint.)

Related

Is it possible to use testcontainer during KSP?

I want to use testcontainer during code generation. I have a project for 2 modules:
processor (with implementation of SymbolProcessorProvider and BuildProcessor)
workload
This is my build.gradle.kts in processor module
plugins {
kotlin("jvm")
}
group = "com.processor"
version = "1.0-SNAPSHOT"
val testcontainers = "1.17.6"
dependencies {
implementation(kotlin("stdlib"))
implementation("com.squareup:javapoet:1.12.1")
implementation("com.google.devtools.ksp:symbol-processing-api:$kspVersion")
implementation("org.testcontainers:testcontainers:$testcontainers")
}
Unfortunately I get this error when I try to run any container:
Script file extensions:
[KOTLIN] Kotlin compilation 'jdkHome' argument: /Users/user/Library/Java/JavaVirtualMachines/adopt-openjdk-1.8.0_302/Contents/Home
i: found daemon on port 17051 (6824097 ms old), trying to connect
i: connected to the daemon
i: [ksp] loaded provider(s): [com.memodict.BuilderProcessorProvider]
e: [ksp] java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
I'm wondering is it possible to use docker during KSP? In my workload module I can use docker in the test without any problem

Gradle build doing nothing on WSL

I'm writing a Kotlin program, and using Gradle as the build system, as is customary in that language. I usually work on Windows, but it's time to start testing on Linux, so using WSL for that. Installed Gradle, cloned a copy of my code in WSL...
(base) a#DESKTOP-4B7M920:~/ayane$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------
Build time: 2012-12-21 00:00:00 UTC
Revision: none
Groovy: 2.4.16
Ant: Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM: 11.0.7 (Ubuntu 11.0.7+10-post-Ubuntu-2ubuntu218.04)
So far so good, that warning happens sometimes, doesn't seem to portend immediate trouble.
This is my build file, that works on Windows:
(base) a#DESKTOP-4B7M920:~/ayane$ cat build.gradle.kts
plugins {
kotlin("jvm") version "1.3.72"
}
repositories {
jcenter()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter:5.6.2")
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
Here goes.
(base) a#DESKTOP-4B7M920:~/ayane$ gradle build
> Task :buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
<-------------> 0% WAITING
Uh? I could understand if it threw an error because some prerequisite or other was unavailable. But no error, just nothing? What's going on?
You are using the newest version at this time of the Kotlin plugin for Gradle (1.3.72). However, you are using a really old version of Gradle (4.4.1). As you can read from the Kotlin documentation:
The Kotlin Gradle plugin 1.3.72 works with Gradle 4.9 and later.
It is unfortunate that the plugin doesn't check for this and give a more proper error message instead of just silently doing nothing. I guess you could create an issue for Jetbrains on this if you like.
Just as has been mentioned in the comment to your question, I also highly recommend using the wrapper. It ensures that the project is built with a particular declared version of Gradle that you, the build author, has decided on. Otherwise, you will have to document how to set up the environment correctly, including what version of Gradle to install.
Same thing goes for Java: be sure to clearly document which version is required or supported.
As for building in WSL, the only issue I've ever had with it was a remote build cache not working. This was because I had configured Git to checkout with POSIX line endings (LF) for source files, whereas the cache were populated on a Windows machine using CRLF line endings). It doesn't sound like you are using that feature, but other than that, everything has been working fine for me in WSL.

gradle nativeBinaries fails to satisfy dependencies

So, I wanted to generate native Kotlin binary for my app. I've came up with this build.gradle.kts:
plugins {
application
kotlin("multiplatform") version "1.3.70"
}
version = "1.0.2"
group = "org.gradle.sample"
repositories {
mavenCentral()
}
kotlin {
linuxX64("native") {
binaries {
executable()
}
}
}
dependencies {
implementation(kotlin("stdlib"))
implementation("io.javalin:javalin:3.8.0")
}
The code itself is simple:
package org.gradle.sample
import io.javalin.Javalin
fun main() {
val app = Javalin.create().start(7000)
app.get("/") { ctx -> ctx.result("Hello World") }
}
Problem here is that it fails when compiling, like if the dependencies were not satisfied:
> Task :compileKotlinNative FAILED
Caching disabled for task ':compileKotlinNative' because:
Build cache is disabled
Task ':compileKotlinNative' is not up-to-date because:
Task has failed previously.
file or directory '/home/keddad/Documents/samplekotlinapi/src/commonMain/kotlin', not found
file or directory '/home/keddad/Documents/samplekotlinapi/src/commonMain/kotlin', not found
Run tool: konanc with args: -g -ea -target linux_x64 -p library -o /home/keddad/Documents/samplekotlinapi/build/classes/kotlin/native/main/basic-api.klib -Xmulti-platform -no-endorsed-libs /home/keddad/Documents/samplekotlinapi/src/nativeMain/kotlin/org/gradle/sample/Main.kt
e: /home/keddad/Documents/samplekotlinapi/src/nativeMain/kotlin/org/gradle/sample/Main.kt: (3, 8): Unresolved reference: io
e: /home/keddad/Documents/samplekotlinapi/src/nativeMain/kotlin/org/gradle/sample/Main.kt: (6, 15): Unresolved reference: Javalin
e: /home/keddad/Documents/samplekotlinapi/src/nativeMain/kotlin/org/gradle/sample/Main.kt: (7, 20): Cannot infer a type for this parameter. Please specify it explicitly.
:compileKotlinNative (Thread[Execution worker for ':',5,main]) completed. Took 0.201 secs.
FAILURE: Build failed with an exception.
Same thing worked when compiling for JVM, but for Native it breaks. What am I doing wrong?
Unfortunately, you will not be able to compile this code at the moment. It seems like the Javalin framework is not targeting Kotlin/Native, it publishes only for Kotlin/JVM. The only libraries published with K/N in mind will be available to use.
In fact, the problem is that Kotlin flavors are not equivalent internally. They can share pure Kotlin code via common... source sets, but one cannot take a Kotlin/JVM project and just change the target. Kotlin/Native differs from the Kotlin/JVM, both of them are not the same as the Kotlin/JS. To make them work together, an approach named Kotlin/Multiplatform is recommended, see this article.
If you are interested in adapting this code to become multiplatform, consider looking at the Ktor. It provides support of the Kotlin/Native, and you'll be able to partially share code between platforms.

Quarkus gradle test fails

I am trying to run the simple 'getting-started'-type gradle project with quarkus and my unit test fails everytime with this error
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to locate project pom.xml for C:\Users\myuser\IdeaProjects\myproj\build\classes\java\main
Followed instructions here https://quarkus.io/guides/gradle-tooling
Any suggestions or thoughts on what is going on?
Gradle version details
Gradle 5.4
Build time: 2019-04-16 02:44:16 UTC
Revision: a4f3f91a30d4e36d82cc7592c4a0726df52aba0d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64
btw. the problem is still open (current version 0.19.1) and issue (2307) is still unresolved.
The reason is that #QuarkusTest points to the QuarkusTestExtension, which in BootstrapClassLoaderFactory.newDeploymentClassLoader attempts to resolve local project with Maven.
We have options:
wait for official solution (see issue)
write own extension overriding BootstrapClassLoaderFactory to "understand" gradle project structure
apply a workaround (for time being), i.e. generate pom.xml from gradle build
Workaround
in build.grade:
plugins {
id 'java'
id 'io.quarkus' version '0.19.1'
// ...
id 'maven-publish'
}
// ...
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// augment your pom here if necessary
}
}
}
// ...
task createPom(type: Copy) {
description 'This is workaround to generate pom.xml, needed for #QuarkusTest tests.'
dependsOn('generatePomFileForMavenJavaPublication')
from "$buildDir/publications/mavenJava/pom-default.xml"
into '.'
rename('pom-default.xml', 'pom.xml')
}
Note:
use 'maven-publish', not obsolete 'maven' plugin.
do not forget to apply ./gradlew createPom on dependencies changes

springfox 2.2.3 snapshot dependencies adding failed because of missing nexus-maven-repository-index.properties

I setup my project with springfox 2.2.3 snapshot version in IDEA 14 with gradle. I follow instruction 2.1.1. Gradle Snapshot. I failed with error that maven repository cannot be indexed and see exception in IDEA's log:
WARN - #org.jetbrains.idea.maven - Failed to update Maven indices for: [com.intellij.util.CachedValueImpl#a1d13c] http://oss.jfrog.org/simple/oss-snapshot-local/io/springfox
org.jetbrains.idea.maven.server.MavenServerIndexerException: java.lang.RuntimeException: java.io.FileNotFoundException: Resource nexus-maven-repository-index.properties does not exist
I tried both repositories and both failed:
http://oss.jfrog.org/simple/oss-snapshot-local/io/springfox/
http://oss.jfrog.org/oss-snapshot-local/io/springfox/
Could anyone have any idea how to fix the issue?
I tried to download dependencies manually and put them in my local .m2 directory and setup in gradle mavenLocal() instead of maven {url ...} but my attempt failed with IDEA's warning on Gradle refresh operation:
Warning:<i><b>project ':data-service': Web Facets/Artifacts will not be configured</b>
Details: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':data-service:runtime'.
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find io.springfox:springfox-swagger2:2.2.3-SNAPSHOT.
Required by:
parseq:data-service:2.4.0 alpha</i>
Now I think that should also manually add transitive dependencies for springfox package. But it looks ugly and I think I should not go this way.
Does anyone has idea what should I do?
I found issues with dependency donwloading:
* when I work from corporate network I have SSL certificate issue
* initially I added maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } into buildscript {...} section, I changed it to repositories {...} and fixed the issue
* also I updated my gradle to 2.4 version (but it didn't help)
Now my starting issue is fixed.