How to recompile gradle dependency from sources? - gradle

We have a dependency dep which was originally compiled in Java 8. The project requiring this dependency is compiled and run with Java 6. This results ``bad major version'' error.
We have the sources available in our central repository for dep and looking for a way that the sources are downloaded in build.gradle:
compile('dep_group:dep_artifact:version:sources')
and then recompile in JDK 6 to produce the required jar file.
Is it possible? Or any suggestions?
Alternatively, we have to download the code of dep offline, recompile with JDK 6, publish the jar file and finally add it as a dependency. But we are looking to avoid this long route. This is just for testing purposes and we do not want to publish a new version compiled with an older version of Java.

Without original build file (POM / build.gradle / ant.xml) you cannot recompile library. If it is a rather simple library - possible option is to include its sources as additional module in multi-module Gradle project:
Download sources
Create folder for them in your project
Create additional module as described in Gradle docs: https://docs.gradle.org/current/userguide/multi_project_builds.html
Apply java plugin for module
Set dependency on this project in format: compile(project(':dep'))
Finally, when you build your project Gradle will compile this module and use it as dependency for your main module.
Do not forget to check library license, e.g. Apache License 2 permits such a simple usage of sources.

Related

How to trigger IntelliJ to reimport single Maven dependency?

I have a workflow working on an application and one of its libraries that somewhat looks like this:
Make changes to library -> Push library jar to remote Maven repository with no version change -> Pull updated library jar from the remote repo to the downstream app -> Test and make changes to the app and library
But seems like the way IntelliJ indexes and/or caches Maven dependencies is not affected by me running a clean install from the Maven interface. Is there a surefire way to force IntelliJ to discard any cached dependency and reimport, or possibly do it only for a desired library?
Very likely this has nothing to do with IntelliJ. Since the version number is the same, maven won't re-download your dependency. Try to just delete the dependency locally from the maven repository:
rm -rf ~/.m2/repository/<..path to your library package..>
You could also avoid pushing the library to the remote repository, and test completely locally, by using the library as a local dependency. For this approach, see answers here: How to add local jar files to a Maven project?
Or since you are not effectively changes the library version the right approach would be to use the library project sources as a direct dependency for IDE maven project. For this - add this Maven library project as a new module to existing Maven project: File | New... | Module from Existing Sources... and select pom.xml file of this library project.

How to pack a jar without dependency classes in gradle similar to maven

How to write a gradle script so that the application jar should be packed without dependency classes similar to maven jar package
The application JAR is always without dependencies, except you use special plugins to create a "fat" JAR where the dependencies are included. If you ask how to set up a Gradle build at all, you should start reading the Users Guide.
If you are trying to package a jar from your Android app or library:
I ran into this question because gradle would include 3rd party libraries into my jar when running gradle assembleRelease.
The contents of the jar then looked like this:
com/android/...
/myCompany/...
For some reason this did not happen when building for debug. Finally I found that changing:
compile 'com.android.support:recyclerview-v7:23.0.0'
to
provided 'com.android.support:recyclerview-v7:23.0.0'
would not include the 3rd party libs ...

Maven integration with native libraries

I am using Android with Maven in my project . It depends on zbar.jar which in turn depends on the secondary artifacts like .so files. I am able to install the zbar.jar in the maven repository , but my secondary artifacts like .so files are not getting pulling through the Maven repository.
Any advice is appreciated.
Maven is designed to handle Java code. The .so files are binaries compiled for a specific architecture.
Are you fully aware on the implications of using .so files?
You can
Either package the so file in a jar file and write custom code to
copy them in their correct position before your application runs
or locate a maven plugin that does what you want. (or even an
Android-Maven specific plugin)
See also Maven2 Dependencies and Native Libraries

Maven to compile projects from source

I am very new to maven. Our project is using maven and i am wanting to know if there is a way to force maven to build using source ONLY? Using no repo and not downloading anything. I have all the source required to build the whole project.
I just want to compile clean with out downloading or using the local repo.
Thanks
Usually not. The main reason is that you don't have all the sources.
Maven is a tool to manage dependencies for you. So you can say: "I need JUnit 4.11" and Maven will download it for you and make sure it's on the classpath when it's needed.
Now, if your project depends on JUnit 4.11, you can't compile it from source without the sources for JUnit. And Hamcrest. And probably a dozen other things.
So, no, you can't. Maven will compile the sources of your project but it won't try to locate the sources of all dependencies and compile them as well. Maven was built with the assumption that the binaries uploaded to Maven Central are correct and that the binaries were built from the attached source files (which are incomplete, btw, so you can't always build the project correctly from them).

Where to download Netflix Astyanax dependencies?

I want to include Astyanax into my project. I checkout the code from github and compiled it with "gradlew build". I am not familiar with gradle.
I include the Astyanx jar files manually into my project. When I run it, it complains about missing Jar.
I wonder, where I can download all the dependencies bundle for Astyanax?
Java library projects often don't provide a single download location for their dependencies. Instead, you would typically use a build tool that supports Maven repositories (e.g. Maven or Gradle) for your own project, which would then automatically download required dependencies behind the scenes.
If you do want to get hold of all dependencies for the Astyanax project, try to add the following to its build.gradle:
task copyLibs(type: Copy) {
from configurations.runtime
into "libs"
}
Running gradlew copyLibs should then copy all (compile and runtime) dependencies into the libs directory.

Resources