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)
Related
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?
I want to use the Google Cloud Storage from Java in App Engine. The documentation on how to install this is very thin. I found the source code for com.google.appengine.tools.cloudstorage but when this source is put into the build path (Eclipse) it generates lots of compile errors. I then track down those sources, add them in and then get more compile errors from more dependencies. It seems like I am missing something about how to use this code in a much simpler way.
You can generate the library jar and also get its dependencies using Java Ant and the direction mentioned here or better yet, use maven and include appengine-gcs-client as a dependency.
If you don't use Maven, right-click on your project > Google > Add Google APIs > Cloud Storage JSON API.
This will add all the dependencies that you need. After that, the only jar you need is appengine-gcs-client.
I have a java library project which contains a dependency to guava library. Guava has near 11k methods count, and I expect most of the users would came from the Android community. On Android there is a limit count method, it is 65k...
But the total count methods of my library is about 11.400, so my library's code is under 200 lines.
I was able to download and shrank a guava jar using proguard, reducing the count method number to 1k. But now the project needs to contain a reference to this shrank jar, instead a reference to the remote repository where the guava is hosted. But any jar added to the project would be discard by maven when it were published at any remote repository as an artifact, so the guava dependencies could not be resolved and the application client ultimately would crash.
Guava itself advices to not use proguard if your “application” is actually a library, and leave to the users of your library deal with this situation, using themselves proguard in order to shrank guava. But I don’t like this idea, because I would like to offer an easy configuration solution.
As far as I know, the output that proguard provides is some sort of executable (jar, apk, etc), so, If I shrank my own library, the final output would be a jar, and this jar, again, could not be published as an artifact, because it would be discarded (I tried it several times).
Is there any way of using proguard in my own java library project and pass the resulting output to the build chain in order to be published as a remote repository, not as a jar?
I’m using gradle by the way to build my project, but at this point I would be up to move to a maven one it that solves the problem.
Thanks.
Do one of the followings:
Use your shrank version of guava as separate maven artifact, publish it, and let your lib depend on it as on any other dependency
Do not shrink the library and use multidex build - this is the
method to solve 65K method limiation
http://developer.android.com/tools/building/multidex.html
Anyway as for ease of configuration you should not use progruard on your library for a simple reason: User will have to add dependency to its project anyway. And what if in some cases users will start having ClassNotFound exception because you have truncated some of the code that you didnt expect it can be used?
If somebody is programing for Android he will sooner or later bang into ProGuard, and I think sooner is better.
So as for ease of configuration, I would rather suggest in the documentation, that if user wants to avoid 65k limitation because your library is already exceeding it, he can use proguard in provided example configuration.
I want to use Jackson JSON parser library in my android project. I saw this library in Maven repository, but I don't know how to use it. I've downloaded sources from the Maven repository and Jackson jars and attached sources to jar, but in the logcat I saw error message NoClassDefFoundError. When googling I' ve read that I have to declare Jackson dependencies in pom.xml file.I' m a newbie in Java development so I don't know what all these means. And have some questions:
1.How to write pom.xml for the Jackson library
2.Where to put this pom.xml
3. Do I really need to install Maven if I just want to use the library.
4. What else I need to begin work with the library?
No, you do not need to write a pom file, unless you are using Maven for building (in which case you need it regardless of Jackson).
What you need are just Jackson jars -- there is more than one, since some projects only need some pieces. This page:
http://wiki.fasterxml.com/JacksonDownload
should show what you need, and where to get them from. If you are starting from scratch, I would strongly recommend using Jackson 2.1 (not 1.9). And then you most likely need 3 jars (jackson-annotations, jackson-databind, jackson-core) -- although minimal is just jackson-core, if you use so-called "streaming API" (low-level, highest performance, but more work).
The benefit of using Maven would be just that you can define logical depenendency (group and artifact id of jar), and Maven would resolve it to physical jar, as well as references to other jars.
I'm new to Maven, using the m2e plugin for Eclipse. I'm still wrapping my head around Maven, but it seems like whenever I need to import a new library, like java.util.List, now I have to manually go through the hassle of finding the right repository for the jar and adding it to the dependencies in the POM. This seems like a major hassle, especially since some jars can't be found in public repositories, so they have to be uploaded into the local repository.
Am I missing something about Maven in Eclipse? Is there a way to automatically update the POM when Eclipse automatically imports a new library?
I'm trying to understand how using Maven saves time/effort...
You picked a bad example. Portions of the actual Java Library that come with the Java Standard Runtime are there regardless of Maven configuration.
With that in mind, if you wanted to add something external, say Log4j, then you would need to add a project dependency on Log4j. Maven would then take the dependency information and create a "signature" to search for, first in the local cache, and then in the external repositories.
Such a signature might look like
groupId:artifactId:version
or perhaps
groupId:artifactId:version:classifier
This identifies a maven "module" which will then be downloaded and configured into your system. Once in place it adds all of the classes within the module to your configured project.
Maven principally saves time in downloading and organizing JAR files in your build. By defining a "standard" project layout and a "standard" build order, Maven eliminates a lot of the guesswork in the "why isn't my project building" sweepstakes. Also, you can use neat commands like "mvn dependency:tree" to print out a list of all the JARs your project depends on, recursively.
Warning note: If you are using the M2E plugin and Eclipse, you may also run into problems with the plugin itself. The 1.0 version (hosted at eclipse.org) was much less friendly than the previous 0.12 version (hosted at Sonatype). You can get around this to some extent by downloading and installing the "standalone" version of Maven from apache (maven.apache.org) and running Maven from the command line. This is actually much more stable than trying to run Maven inside Eclipse (in my personal experience) and may save you some pain as you try to learn about Maven.