Google Cloud Storage Java Client Library with Gradle - java

Google promotes their new Java Client library here: https://developers.google.com/appengine/docs/java/googlecloudstorageclient/
Note: I am not talking about the native REST library. I want to work with the Java Client Library.
On the website, Google does not specify the import directive for Gradle. For Maven, pom.xml looks like this:
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>RELEASE</version>
</dependency>
When I change this to work with my Gradle project, it doesn't work:
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:RELEASE'
}
It finds the tools there, but the com.google.appengine.tools.cloudstorage cannot be resolved (it resolves tools, though).
What I did then: I removed the library and seached for "gcs" in the Android Studio dependencies dialog; and it finds and adds the following directive to build.gradle:
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:0.3.9#jar'
}
Same problem with that as before: tools is resolved, but not tools.cloudstorage.
What am I doing wrong? Where does the library live/which import statement will I need to add to Gradle?
I don't want to download the jar as I want my project to update jars automatically. mavenCentral() is set, and here is my full build.gradle file, just in case you need it:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:0.3.9#jar'
compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
}
Any help appreciated, thanks!

You can use the following to specify version 0.4.4 (the most recent as of 1/14/2015):
compile 'com.google.appengine.tools:appengine-gcs-client:0.4.4'
or specify the latest version with a plus sign:
compile 'com.google.appengine.tools:appengine-gcs-client:+'
Using the latter is the faster answer, but it may cause unintended compatibility issues in the future as updates are release.

Related

How to import 3rd party library using mavin into Java project using gradle?

I want to use the sxcml-java library in my son's school's robotics code (currently a private repo).
The library uses Maven. I was able to successfully include the library in a test project using Maven.
However, I've just discovered that the existing robotics project code uses Gradle. I don't know either Maven or Gradle, and I haven't programmed in Java in almost 30 years.
How can I most easily use scxml-java - which itself has external 3rd party dependencies — in the robotics project?
This question is similar to this one, but the solution there was easy because both projects were using Gradle.
Provided the package is published in an artifactory, which is the case (See here), you can just include it as any other Gradle dependency (using groupId, artifactId and version), regardless of what build system was used to build it in the first place.
dependencies {
implementation 'com.nosolojava.fsm:scxml-java-implementation:1.0.1'
}
If you use IntelliJ IDEA, pasting the Maven dependency block into the build.gradle file will automatically convert it into the Gradle dependency format like the one above.
Please note however this does not apply to plugins, only to regular dependencies.
If You install your jar or third party jar into maven local repo like ~/.m2
you can add mavenLocal()
repositories {
mavenCentral()
// * Require by Use JAR install to Maven Local Repo your .m2
mavenLocal()
}
then add implementation to dependencies
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
implementation 'yourGroupId:yourArtifactId:yourVersion'
}
Please mapping yourGroupId , yourArtifactId, yourVersion from your pom.xml
If You only download third party jar into foler like /home/yourName/your-libs
you can add configurations
configurations {
sxcml-java-lib
}
then add dependencies
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
//sxcml-java-lib fileTree(dir: "${System.getProperty("user.home")}/libs", include: "*.jar")
sxcml-java-lib fileTree(dir: "/home/yourName/your-libs", include: "*.jar")
}

How do I add libraries to my Gradle file?

It's probably very simple, but only to people who know what they are doing.
I have a Java program that imports these two:
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
As an aside, I don't want to use the lang3 package but the lang package.
I do not have anything in my Gradle file about these. When I try to build the file, it gives me errors for these two, saying the packages do not exist.
My questions are:
Do I need to add them as "compile" or as "api"?
What is the exact syntax? I have lines that look like this:
api group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
How do I find the right name (or should I just invent one)? and the version?
Anything your code needs (besides basic JRE classes) is a dependency for your code. Gradle manages these dependencies, usually downloading them from a repository.
First you need to find such a repository. You probably have repositories already configured in your build.gradle, like so:
buildscript {
repositories {
mavenCentral()
// maybe more repositories
}
}
That means Gradle will try to download dependencies from Maven Central. You can either do a web search for "gradle" and your dependency, or go to repository and search, or check the dependency's homepage.
You'll end up with a dependency name and version like 'org.apache.commons:commons-lang3:3.12.0'. This needs to go in your build.gradle.
Gradle has different dependencies:
buildscript dependencies provide code that Gradle needs to execute to build your project, e.g., a tool to pull in version control system information or generate code
implementation dependencies are dependencies your code needs to run, like a logging framework or JSON parser or PDF generator
test dependencies are dependencies needed to run your automated tests, like JUnit
Depending on where you need the dependency, you put it in the buildscript or the dependencies block.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.tmatesoft.svnkit:svnkit:1.9.+'
}
}
dependencies {
implementation 'pdfbox:pdfbox:0.7.3'
testImplementation 'junit:junit:4.+'
}
You don't need to repeat the implementation dependencies for the testImplementation btw, as it inherits them automatically.
You can define your own configurations as need; see the Gradle manual on dependencies, for example if you have different test suites (unit, integration, performance, ...) that need different dependencies.
you'll have to go to their official website and get the implementations then add those to the dependencies(you'll find it at the bottom of the file) in the build.gradle(module) it would look something like -
the $lifecycle_version might be somethiing like 1.2.3 or some version number.
this is what I got (not exactly sure if this is right)-
implementation 'org.apache.commons:commons-lang3:3.12.0'
got from library website in the gradle short tab
in the build.gradle(project), look for maven repo.
Once done, you'll be able to import the respective libraries.

Firebase dependency isnt showing up?

So I've tried adding Firebase dependency to my gradle project. But it doesn't seem to be working. It adds fine, there's no errors or anything and I can see the firebase jar in my Referenced Libraries. But whenever I try to import anything from it like import google.com.firebase, it doesn't show up. What am I doing wrong? These are the only imports I'm seeing.
This is my repositories thing in build.gradle
repositories {
mavenCentral()
google()
jcenter()
}
This is my dependencies thing
dependencies {
compile 'com.google.firebase:firebase-database:19.3.1'
}
So basically, the dependency adds correctly I think, it does show up on the Referenced libraries on my IDE but I don't know why I cannot access it?
Btw I'm not making an Android app, it's a mod for minecraft that uses forge gradle.
Also this is my gradle version: https://services.gradle.org/distributions/gradle-4.1-all.zip
It was because i used an dependency meant for android developers with the aar extensions so instead of using
compile 'com.google.firebase:firebase-database:19.3.1'
In dependencies in build.gradle using this which is meant for the java thing works now.
compile 'com.google.firebase:firebase-admin:6.16.0'

Create single AAR file from multiple modules using Gradle in Android Studio [duplicate]

I am building android library project, which has a dependency on another internal library project.
I am wondering if there is a way to package a single AAR library, which already contains internal library inside it. I would like to share only 1 AAR library package to my application developers.
This is how my build.gradle files look currently, but currently they produce separate AAR files and both needs to be included in Application's build.gradle. As application is being built by another company, we need to share the final AAR file with them and not the complete library projects.
----- internalLib -------->>>>>>>>>>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
----- externalLib --------
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':internalLib')
}
There is no mechanism to combine library. It's a bit complicated as you probably want to control which dependencies get merged (for instance you probably don't want to include support-v4 in there). Also you'd need to merge the resources and Android manifest.
At this time there's no way to easily hack something, unless you are sure the resources have no conflicts between the two res folders (for instance you could have strings_a.xml in one lib and strings_b.xml in the other lib). This way you can just "merge" the two res folders by copying them both into the same location (as opposed to do a merge at the android res level).
For the Manifest it'd be more complicated, but doable with some custom code.
Providing a built-in mechanism for this is very low on our priority so don't expect it anytime soon.
For the sake you have to upload each library as separately on maven and use its implementation in parent library modules till the main library module. Only then when you publish your main library on maven will include your all child dependencies.
As far as we have only one option add aar as api dependency inside the module.
For that we have to generate aar file and publish it to Maven and make it accessible by another module and consume it in app.
https://developer.android.com/studio/projects/android-library
As mentioned above android developer document.
The library module with source code is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
If there anything else we can do, please let us know by jot down in the command section.
It is not supported
It is not recommended to include one library into another because it leads to a serious issues with managing versions and complexity of creating and supporting such solution.
You should stick to native approaches like dependency manager or rearchitect your codebase
[iOS Umbrella framework]

Android 3rd Party Library Integration

this is kinda crazy. I already worked often with 3rd party librarys. All I had to do was adding the compile command in the build gradle but in this case its something different. This is the github link of the lib i want to implement:
Link to github
I tried to integrate the files I need manually but i got a amount of errors.
In the README the developer says:
This library is provided as the AAR format. The source jar file won't be downloaded automatically (due to the current Gradle and Android Studio limitation), so javadoc comments are not displayed on IDE.
Can somebody help me how to integrate this the best way.
If you have a look below, they have already provided a workaround
buildscript {
repositories {
maven { url 'https://raw.github.com/xujiaao/mvn-repository/master/releases' }
}
dependencies {
classpath 'com.github.xujiaao:aarLinkSources:1.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'aar-link-sources'
android {
...
}
dependencies {
compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.0#aar'){
transitive=true
}
aarLinkSources 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.0:sources#jar'
}

Categories

Resources