How to resolve the DNS issue with GCP Pub/Sub - java

Background:
I'm working on creating a messaging library that basically abstracts GCP Pub/Sub. Accordingly, I am creating a fat JAR with relocated packages, and this fat JAR is imported in other projects. The point to isolate the fat JAR's dependencies from those of the importing projects.
When I test this locally from an IDE, the fat JAR works fine. However, when I export a project to a JAR and run it, I get the following error.
I have also checked the logs and found the following which I have found in this issue that these configurations are correct.
Is there something wrong with the address provided here, or should I configure anything on my end?
These are the dependencies I'm fetching for the library via Gradle.
implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.40.1'
implementation group: 'io.perfmark', name: 'perfmark-impl', version: '0.25.0'
implementation group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '1.114.6'
implementation group: 'io.grpc', name: 'grpc-context', version: '1.42.2'
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jApiVersion}"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
Thanks.

Related

Why does my java project still work even though its missing some packages?

I am working on a Dubbo project and when I digging a little deep into its source code. I found these code in Dubbo's source code:
I think this shows that my project missing the org.jboss.*package
(IDEA has mark these packages in red)
But somehow this project still working, doesn't it supposed to not working due to it has some package missing?
By the way my project is organized by gradle and the build.gradle is like this:
dependencies
{
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile group: 'org.apache.dubbo', name: 'dubbo-spring-boot-starter', version: '2.7.8'
compile group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.6.2'
compile group: 'org.apache.curator', name: 'curator-framework', version: '5.1.0'
}
If this wouldn't be some library's de-compiled byte-code but your application's source code, this would rather be an issue. And it's not missing anything, but Gradle will pull in org.jboss.netty on demand, which will then pull in another 8 libraries, which may evetually even pull in further libraries.

Need to include org.json packages in MVC portlet to parse JSON in Liferay 7

Iam having a MVC portlet created using gradle, I want to parse JSON in it, so I included following packages like below,
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONValue;
Also I have included org.json in build.gradle file as you can see below:
dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "3.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "jstl", name: "jstl", version: "1.2"
compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
//compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.6.0'
compile group: 'org.json', name: 'json', version: '20180813'
compile group: 'org.apache.clerezza.ext', name: 'org.json.simple', version: '0.4'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
}
Compiling was successful but while deploying it in Liferay(7), Iam getting the below error:
While deploying in Liferay am getting this error:
org.osgi.framework.BundleException: Could not resolve module: mvc [952]_ Unreso
lved requirement: Import-Package: org.json; version="[20180813.0.0,20180814.0.0)
Should I include the package org.json inside liferay as well? If yes where should I add it?
I couldn't add any new packages Please anyone help me on this.
When you declare build-time dependencies to libraries that are not made available in Liferay out of the box (be it for the library itself, or for the specific version), the compiler will be happy, and bnd will generate (if required) runtime dependencies into your module's Manifest.mf.
If indeed these dependencies result in runtime dependencies, you'll have to make the libraries available to the OSGi runtime (Liferay in this case) as well. You do that in the same way you're deploying your own modules: Just drop them into Liferay's deploy folder.

Migrate maven dependencies to gradle

I start with software testing - using Cucumber, Java, gradle.
I try to learn this with the book "The Cucumber for Java Book"
But I try to do I with gradle instead of maven... But now I have some problems...
I stick on page 149. I have to give so dependecies:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
I try to "translate" this to gradle
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'io.cucumber:cucumber-java:2.4.0'
testCompile 'io.cucumber:cucumber-junit:2.4.0'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
}
Is this right?
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
After that I have to run:
mvn exec:java -Dexec.mainClass="nicebank.AtmServer"
But how can I do this with gradle?
I hope someone can help me :)
Your dependency looks good. Just one note: consider using implementation over compile as it improves the performance. Read about compile deprecation here.
You can also put your properties in gradle.properties file and reference them in the build script:
gradle.properties:
jettyVersion=9.4.12.v20180830
build.gradle:
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: jettyVersion
Jetty team also published BOMs: — org.eclipse.jetty:jetty-bom:9.4.12.v20180830 in your case. If you use multiple projects of the same version you can import the BOM and skip the version completely:
dependencies {
implementation 'org.eclipse.jetty:jetty-bom:9.4.12.v20180830'
implementation 'org.eclipse.jetty:jetty-webapp'
implementation 'org.eclipse.jetty:jetty-runner'
}
As for the "exec" task: if you have only one main class in your project, like nicebank.AtmServer, consider using Gradle's Application Plugin:
plugins {
id 'application'
}
mainClassName = 'nicebank.AtmServer'
This way you don't need to create "exec" task manually, you'll get one (run) from the plugin. As a bonus you'll get two "distribution" tasks that will create a ready-for-distribution archive with your app: distZip and distTar.
As I said in my comment, the dependency for jetty-webapp seems OK but you should use implementation instead of compile ( compile has been deprecated, see Java dependency configurations):
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
or
implementation "org.eclipse.jetty:jetty-webapp:9.4.12.v20180830"
For the equivalent of "maven exec:java" in Gradle , you could use the Gradle JavaExec task type: try to define a task in your build as follows:
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'nicebank.AtmServer'
}
(not tested, you migth have to adapt it) , and run it with
gradle runApp
You could alternatively use Gretty plugin to run your webapp (no need to define your own JavaExec task in this case), as documented here and here:
plugins{
// your existing plugins
id "org.gretty" version "2.2.0"
}
You can then run the application with:
gradle appRun

Cannot exclude module from build.gradle

I'm trying to exclude some modules from my build.gradle file but it(code1 and code2) still downloads the excluded files.
code 1:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude group: 'com.amazonaws', module: 'aws-java-sdk-machinelearning'
}
code 2:
compile (group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.7') {
exclude module: 'aws-java-sdk-machinelearning'
}
when I tried using the following code,
configurations {
compile.exclude module: 'aws-java-sdk-machinelearning'
}
it excludes the files but I don't want to use this method to exclude files
I second/confirm with #Opal that code1 works fine in Gradle 2.13.
What is likely happening is that you have some other (maybe non-aws) dependency, that may be transitively using aws-java-sdk which then brings in the machine-learning dependency. Which is why, it works fine when you do a global exclude, but not when you do a local exclude on just aws-java-sdk.
Try running gradlew dependencies --configuration=compile to get a tree of dependencies, including transitives, to check which dependency might be bringing in aws-java-sdk-machinelearning

Using JavaCV and Realm together causes "java.lang.UnsatisfiedLinkError"

I have recently been getting the following error by attempting to start an instance of JavaCV's FFmpegFrameGrabber:
java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at org.bytedeco.javacpp.Loader.load(Loader.java:413)
at org.bytedeco.javacpp.Loader.load(Loader.java:381)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2597)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:386)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:380)...
While solutions to this problem exist, none worked for me.
Through many trials i have discovered that weirdly enough, if i do not include Realm in my project, i no longer receive this error.
Here is the part of my build.gradle file in which I include all of these libraries:
compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-x86'
// ORM
compile 'io.realm:realm-android:0.87.2' // Tested NOT OK - Causes JavaCV to crash
//
I am thinking that there may be a solution to this problem that i am not aware of. I found no mention anywhere on the internet about library incompatibility or why this behaviour may occur.
I will edit this post with any additional details that anyone might need.
Any help would be greatly appreciated.
EDIT
I attempted to apply the fix described here.
Now my packaging options look like this:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
exclude "lib/arm64-v8a/librealm-jni.so"
}
Unfortunately, this change has no effect. I'm still stuck.
With the help of one of my coleagues i have been able to solve this issue.
In adition to the steps described in the question, we:
Copyed all of the .so files in the app/src/main/jniLibs/armeabi and app/src/main/jniLibs/armeabi-v7a folders
Added
ndk {
abiFilters "armeabi-v7a"
}
to the defaultConfig part of the module's build.gradle file
Added
lintOptions {
abortOnError false
}
to the android part of the module's build.gradle file
I will try to provide further clarifications to anyone that needs them if i am able.
Firstly this issue occurs because of Gradle doesn't resolve dependencies properly from maven profile ..In my case only x86 depdendecies shipped to APK. that means code above works only on x86 cpu architecture. solution should be done on Android Studio. but as workaround I did this:
Download binary javacv-platform-1.3.1-bin.zip. It's from: https://github.com/bytedeco/javacv
Inside directory javacv-bin copy these jars to new directory
ffmpeg-android-arm.jar
opencv-android-arm.jar
ffmpeg-android-x86.jar
opencv-android-x86.jar
For 2.1 2.2 files, Extract these jars and go to lib then or armeabi. Then copy all *.so files into your project under:
app/src/main/jniLibs/armeabi/
app/src/main/jniLibs/armeabi-v7a/
you might do the same with 2.3 * 2.4 jars by copying dependencies into app/src/main/jniLibs/x86/ . just check your apk if it really doesn't have them.
That's it.

Categories