Android Studio java module dependancy from local directory - java

I have a question regarding whether module dependencies in a java app built in Android studio can be sourced from a local directory instead of an online repository. The code in question is in build.gradle and looks like this:
dependencies {
implementation 'org.hibernate:hibernate-core:3.6.7.Final'
}
This will pull files from a repository into the project at build time. But say I would like to download the dependency (say, from GitHub) and store it locally on my file system and include it into the project from there. How would this be done?
I've tried the following:
dependencies {
implementation '~/path/to/files/'
}
But I get the error Supplied String module notation '~/path/to/files/' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'. (where ~/path/to/files/ is a real path)
The reason I ask is because I'd like to use a library in my project and include it as a dependency. The library is on GitHub. But I'd like to make some changes to it before it's imported. The only solution I can think of is to download it, make the changes and then uploaded as my own forked library back to GitHub again and it include that. But if I can somehow just work on it locally, I'd prefer that. Any ideas?

Related

How can we include dependency library in C# xunit integration test project

I am new to the C# and i see that in xunit project i can add nuget packages. My question is around its use by different team members when code is pushed in git hub/azure.
I can add nuger packages like specflow, dependecy injection and work locally but how can i ensure that when i push code in github or azure next team member who clones repo can also use or see the packages added? is there any mechanism in C# like in java Maven we have pom.xml or gradle.build file or it happens automatically in C#
The nuget packages are added to your .csproj file (before that there was a dedicated packages file). When someone pulls your changes and builds the solution, those packages will be downloaded automatically.
See here: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
Here is a good explanation, how nuget packages are working in Visual Studio.
After cloning/pulling from Github, a "Package Restore" might be necessary:
https://fossa.com/blog/dependency-management-visual-studio-nuget-beyond/#Restoring

Java Gradle Missing libraries Modue that exists or have been imported - > Task :compileJava

So I have been facing these issues in so many JavaFX Gradle based projects in Intelli J Idea IDE. This has pushed me to the point where I had to manually download library files and make them part of my projects as a workaround.
The gradle projects I have they keeping failing when ever i run the > Task :compileJava in the IDE, for example in this particular that made me create the issue is that i have successfully imported the socket io lib from maven implementation 'io.socket:socket.io-client:2.0.1' , i have managed to import it and write a bit of sample code for it and i have added
requires engine.io.client;
requires socket.io.client;
in the module info file . So when its time to run this fails stating that
error: module not found: socket.io.client
requires socket.io.client;
error: module not found: engine.io.client
requires engine.io.client;
I have tried on JDK 13,16,17 to see if I am missing something but keeps on failing to run , so I have noticed now as a trend in my previous JavaFX project in which i managed to get away with.
So if there is anyone who understands what's wrong with Gradle set up please help.
This answer outlines an approach rather than a concrete solution.
socket.io.client and engine.io.client are not module names.
The socket.io-client library is not Java platform modularized (as far as I can tell), so it will be an automatic module.
The name of the module will be derived from the jar name. I don't know the exact translation as the jar name has . and - characters which may be remapped (or not) to make the module name valid. Try first the exact jar file name. There can be only one module per jar.
Additionally to requiring the right name, the jar needs to be on the module path. Maven will do this automatically for automatic modules, Gradle will not. I am not a Gradle expert, so will not provide advice on how to do that for Gradle.
If you use the right name in module-info and ensure the jar is on the module path, then it may work, or it may be incompatible with the Java module system in ways that are not easily fixable by you (i.e. the broken module must be fixed by the module maintainers).
You can raise an issue for the library maintainer for them to create module-info.java files for the modules and update their documentation on how to use their libraries in a Java module environment.
If the library you are trying to use is incompatible with the Java module system when used as a module, then you could try making your project non-modular by deleting module-info.java from your project and adding appropriate command-line switches. To understand how to do this, refer to documentation on non-modular projects at openjfx.io.

Publish jar to maven local and use this dependency in root project

Update
I would like to use external library that is not available on maven repository.
Currently, I have subproject called libs and within CLIPSJNI.jar
In Gradle.build of root project I declare dependency like this
dependencies {
implementation files('/libs/library.jar')
}
but in order to run java application I also have to add file with .jnilib.
My question is it possible to publish to maven local this jar and reuse this dependency. So that .jnilib is redundant.
Initial question was resolve. If you wanna use CLIPSJNI in java application there are only 2 steps you should follow, which are described in comments down below.

How to download Gradle dependency from java code?

My Java application needs to copy artifacts from Artifactory to AWS S3 temp bucket on demand (application group, name and version will be passed as parameters at runtime). The simplest way would be constructing URL and downloading files directly from Artifactory, but application should support 'latest.integration' and 'latest.relase' versions. So I want to add Gradle binaries to the classpath and use it to download dependencies.
Google results overflown with questions about dependency management using build.gradle.
So far I saw https://discuss.gradle.org/t/execute-gradle-task-from-java-code/21859/4 but looks like it also relies on preexisting build.gradle file.
So the question is: is there any way to use Gradle API from Java application to download certain lib without generating build.gradle file?
You should be able to use Ivy (http://ant.apache.org/ivy/) either as is or as a library itself to accomplish what you need, possibly with a bit of additional code.
(answer created from my comments)

Android Library Project without sources

I've created Android Library Project which depends on three libraries : google-play-services_lib, android-support-v7-library and pull-to-refresh ( https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java )
I marked my project as library and want to create jar which can be used as jars are used is google_play_services and android-support library. My question is what I have to do to be sure that libraries that my project depends on are not included in my jar. I want 3rd person - who will use my library - to add them with my projectes as dependencies and get it work.
Unchecked export options in java build path is enough?
I don't know exactly if you have used Gradle or not. But if it's the former, then you don't have to do nothing. If you have include your dependencies in your library project like this:
dependencies {
compile 'whatever:library'
}
Then it's ok.
Note: If your project includes resources (like layouts and more) it can not be compiled as a jar!
Note2: If you didn't use Gradle, notify me in the comment and I'll update this post explaining how to achieve that.
UPDATE 1:
First of all, let me link you to another related answer I did the last week. It gives you useful links to learn Gradle in a hurry (at least all the basics).
Second, do you use Android Studio?
UPDATE 2:
It's just a matter of taste ;)! But with Android Studio (Intellij) you don't need to configure the extra step to get Gradle working.
Well, after you have read those links I've put before, the next step is to create a library project (in Android Studio it will generate the required folders/files automatically for you).
In your lib or library folder (where you put your source code of your library) in your build.gradle put the following:
dependencies {
compile 'com.google.android.gms:play-services:4.4.52'
compile 'com.android.support:gridlayout-v7:19.1.0'
compile 'it.sephiroth.android.library.fork.actionbarpulltorefresh:actionbarpulltorefresh:0.9.92'
}
And with that you can generate your library in aar format.
NOTE: Android-PullToRefresh library is not Gradelized, so I had to search for another alternative that has been uploaded to MavenCentral (like sephiroth's one). Remember to use Gradle, please! To search already Gradelized libs!

Categories