Setting up JNA in Gradle Project - java

I try to import a custom .dll inside my Gradle project. I add the dependencie inside build.gradle
dependencies {
implementation group: 'net.java.dev.jna', name: 'jna', version: '5.6.0'
}
but when I try to run the gradle build I receive this error
..java:170: error: cannot find symbol
CustomLibrary INSTANCE = (CustomLibrary) Native.load("xxx", CustomLibrary.class);
^
symbol: method load()
location: class Native
1 error
Any suggestions?

You have a transitive dependency on an older version of JNA in another dependency.
As you have tagged this with spring boot that is the likely cause. Older Spring Boot versions used a 4.x (I think 4.3) JNA dependency and the syntax has changed.
The POM for Spring Boot uses a property jna.version that you could override if you were using Maven, but I don't think that is (easily) possible using Gradle. However, updating to the latest version of Spring Boot should solve your problem.

Related

updating gradle version for a project that depends on another shared library project doesn't work in a toolchain (kubernetes)

I'm getting this error while trying to commit my changes into gitlab repo and deploy it in kubernetes after upgrading gradle version to 7.4
Also I think the problem in how I include my shared library inside the project it self, that's what I sense from the error output below
Could not determine the dependencies of task ':distTar'.
Could not resolve all task dependencies for configuration ':runtimeClasspath'.
Could not resolve project :vlc-shc.
Required by:
project :
> No matching configuration of project :vlc-shc was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
- None of the consumable configurations have attributes.
build.gradle:
dependencies {
implementation project(':vlc-shc')
}
setting.gradle:
rootProject.name = 'vlc-myProject'
include ('vlc-shc')

Maven quarkus project cannot run quarkus:dev after upgrade to 2.4.0.Final

I'm trying to upgrade a multi-module Quarkus project from 2.2 to the latest 2.6.1.Final. The build (including quarkus:dev with -Psomeproject) works on 2.3.1.Final, but when I upgrade to 2.4.0.Final it fails with this error:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "io.quarkus.deployment.dev.DevModeContext$ModuleInfo.getMain()"
because the return value of "io.quarkus.deployment.dev.DevModeContext.getApplicationRoot()" is null
at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:151)
at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:63)
Caused by: java.lang.NullPointerException: Cannot invoke "io.quarkus.deployment.dev.DevModeContext$ModuleInfo.getMain()" because the return value of "io.quarkus.deployment.dev.DevModeContext.getApplicationRoot()" is null
at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:91)
A regular build still works; it is quarkus:dev that fails. I simply can't see what's wrong here. What am I missing?
I'll create a minimal solution with the problem as the next step, but would appreciate any pointers.
The project is using Java 17 but the regular build does work and development mode also worked with the older platform.
In order to run Quarkus you have to have the correct version of Quarkus itself, and it's helper build plugin.
Ex. of configuration in gradle:
plugins {
// keep the version the same as the quarkus universe bom
id 'io.quarkus' version '2.12.0.Final'
}
dependencies {
api platform("io.quarkus:quarkus-universe-bom:2.12.0.Final")
//... other
}
Make sure that your project dependencies are correct, and the Quarkus plugin nor Quarkus versions are not overridden. Especially check for transitive dependencies, if they do not smuggle some older Quarkus version. For maven:
mvn dependency:tree
// for gradle wrapper:
./gradlew dependencies
// for gradle:
gradle dependencies

Missing dependency on EmbeddedKafka on integration test with groovy and spock

I've been trying to create an integration test using the embeddedKafka, but I'm getting problem of missing dependency when trying to run it, this is the error:
Unable to load class org.springframework.kafka.test.EmbeddedKafkaBroker due to missing dependency org/I0Itec/zkclient/serialize/ZkSerializer
I saw some stuff saying that this is related to my dependencies, so here is my dependencies:
springBootVersion = '2.3.5.RELEASE'
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.kafka:spring-kafka:${springBootVersion}")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}",
'org.spockframework:spock-core:1.2-groovy-2.4',
'org.spockframework:spock-spring:1.2-groovy-2.4',
'com.microsoft.azure:spring-data-cosmosdb:2.3.0',
'com.nimbusds:oauth2-oidc-sdk:5.64.4',
)
testCompile("org.springframework.kafka:spring-kafka-test:${springBootVersion}")
So, my question is, am I missing something?
EDIT
After changed the versions as indicated, I got a different error:
Error creating bean with name 'embeddedKafka': Invocation of init
method failed; nested exception is java.lang.NoClassDefFoundError:
scala/math/Ordering$$anon$7
I've added the scala dependencies, but still having the same issue:
testImplementation("org.scala-lang:scala-library:2.12.11")
testImplementation("org.scala-lang:scala-reflect:2.12.11")
You somehow have a mismatched kafka Vs. kafka-clients jars on the classpath; they all must be the same version.
You generally should not specify a version on boot's dependencies and use its dependency management instead.
You are pulling in spring-kafka 2.3.5 whereas spring-boot 2.3.5 requires spring-kafka 2.5.7.
Spring-kafka 2.5.x uses the kafka-clients 2.5.1.
See here for how to override versions of kafka jars when using a different version to the version that Boot prescribes.
the Kafka Client libraries for a time were inlining a particular version of the Scala library. This caused problems for those of us wanting to use the kafka client library with a slightly different version of Scala than that inline version.
In this cases the version of Scala they were using inline is Scala 2.12.10
They removed this dependency in later versions and this was backported as fixes (the earliest being 2.8.0) https://archive.apache.org/dist/kafka/2.8.0/RELEASE_NOTES.html)

Spring Boot 2.0.0 , DataSourceBuilder not found in autoconfigure jar

We are upgrading our existing Spring Boot (1.5) application to 2.0.0.
We connect with multiple databases and use the org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder class.
I added the dependency:
compile group: 'org.springframework.boot',
name: 'spring-boot-autoconfigure',
version: '2.0.0.RELEASE'
However, I am not able to compile the project: This class (DataSourceBuilder) does not exist in the 2.0.0 version jar.
In order to rule out gradle issues, I manually downloaded the jar and added it to the classpath. This class does not exist in the version.
Also extracted and searched the jar but this class is missing.
Can anyone help me resolve it?
The class was moved to another package. Its FQN is now org.springframework.boot.jdbc.DataSourceBuilder: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/jdbc/DataSourceBuilder.html
Old class (Spring Boot 1.x)
org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
New class (Spring Boot 2.x)
import org.springframework.boot.jdbc.DataSourceBuilder;

Grails NoSuchField exception because of wrong denpendecy version of apache http core

I have Grails 2.0.4 application that depends on a jar that depends on org.apache.httpcomponents:httpcore:4.3.1
I'm getting a NoSuchField exception which I managed to track down to org.apache.http.impl.conn.BasicLineParser.INSTANCE.
This field is only present from httpcore 4.3, before this version the field was BasicLineParser.DEFAULT instead
My BuildConfig.groovy is like:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.16'
runtime 'org.apache.httpcomponents:httpclient:4.3.1'
runtime 'org.apache.httpcomponents:httpcore:4.3.1'
}
Running the dependecy report I found out the there is a signpost-commonshttp4 by oauth.signpost that depends on httpcore:4.0.1 which is probably the root cause of my issue, because it doesn't have the INSTANCE property.
I've tried to exclude this dependency adding
runtime('oauth.signpost:signpost-commonshttp4:1.2.1.1'){
excludes 'httpcore'
}
with no success.
Is there any other way to prevent the code to use the older library version?
Regards
RESOLVED
I managed to resolve this issue adding an extra dependecies configuration
build 'org.apache.httpcomponents:httpclient:4.3.1'
build 'org.apache.httpcomponents:httpcore:4.3.1'
along with the runtime
Thank you all

Categories

Resources