How to start using tensorflow-lite in a gradle-Project? - java

I am trying to import tensorflow-lite to my Java - Gradle Project but when I import the dependency IntelliJ tells me: "Unable to resolve org.tensorflow-lite:0.0.0-nightly"
How can I import tensorflow-lite to this simple Project?
this is my build.gradle:
plugins {
id 'java'
}
group 'com.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
}

Using maven repository as reference you should put your graddle reference like this
compile group: 'org.tensorflow', name: 'tensorflow-lite', version: '0.0.0-nightly'
reference:
https://mvnrepository.com/artifact/org.tensorflow/tensorflow-lite/0.0.0-nightly
You really wanna use the nightly version? This version is unstable like a "beta version"

Related

how to setup error prone with gradle (getting various errors)

I am trying to setup error prone using gradle, however everything ive tried gives me some kind of error:
To test I have setup a simple hello world java program using gradle, which without error prone compiles fine.
Then I read: https://github.com/tbroyer/gradle-errorprone-plugin
found from the install guide and tried this in the build.gradle:
plugins {
id 'java'
id("net.ltgt.errorprone") version "2.3.3"
}
group 'test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
errorprone("com.google.errorprone:error_prone_core:2.3.3")
}
This gave me this error:
Plugin [id: 'net.ltgt.errorprone', version: '2.3.3'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:2.3.3')
Searched in the following repositories:
Gradle Central Plugin Repository
I changed 2.3.3 to latest.version and got the same error
Then I found this https://plugins.gradle.org/plugin/net.ltgt.errorprone and tried version number 0.8.1.
I need to be able to use java11 so can't use gradle 4.x as far as I understand.
Also if anybody knows of an actual repository that has used error prone with gradle that I could look at I would be very grateful :)
My gradle wrapper properties is set to use gradle version 5.4.1
Solved as below
Add Gradle plugin to build.gradle file
plugins {
id("net.ltgt.errorprone") version "1.1.0"
}
Release versions
Add dependency to error_prone_core in build.gradle file
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.3.3")
}
Releases
3. Build project, this will add errorprone configuration namespace
4. If you are using java-8, need to add additional dependency too.
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
along with dependency in step-2.
5. you can customize/enable/disable it by tasks
tasks.withType(JavaCompile).configureEach {
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.enabled = false // change it to true to enable
}
Note: As mentioned in OP comment by #jb-nizet, gralde plugin and error_prone_core has different versions and independent release cycles.
my build.gradle file
buildscript {
ext{
errorproneVersion = '2.3.3'
}
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id "java"
id("net.ltgt.errorprone") version "1.1.0"
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.enabled = false
}
Ref
Github-error-prone

How to use gradle 'api' dependency

I tried using the 'api' dependency keyword in my project , but I got this error saying it cannot find method api()
I tried it on a new project. this is the build.gradle file:
plugins {
id 'java'
}
group 'com.test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
api group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'
}
I am using gradle V4.9.
when I run gradle build I get this:
Could not find method api() for arguments [{group=com.google.guava, name=guava, version=27.0.1-jre}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
If I replace 'api' with 'implementation' everything works fine
What am I missing here?
Is there any setting that needs to be done?
The api configuration comes from the java-library plugin, in your build script you have just applied java plugin. See https://docs.gradle.org/current/userguide/java_library_plugin.html
The key difference between the standard Java plugin and the Java Library plugin is that the latter introduces the concept of an API exposed to consumers. A library is a Java component meant to be consumed by other components. It’s a very common use case in multi-project builds, but also as soon as you have external dependencies.
Just apply the java-library plugin (which extends java plugin) and it should work:
plugins {
id 'java-library'
}
For those using kotlin build scripts use the following:
plugins {
id("org.gradle.kotlin.kotlin-dsl")
}

Gradle IntelliJ add java dependencies

I have created new Gradle Java project on IntelliJ and added the library like normally do in Android Studio.
Gradle is not getting the library and compiling it.
Build file.
group 'asynjava'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "io.reactivex.rxjava2:rxjava:2.x.y"
}
I couldn't import the library inside my java files.
Is there any settings I have missed ?
compile 'io.reactivex.rxjava2:rxjava:2.1.2'
You have to specify the complete version info, the minor version numbers in particular.

Is there a way to download dependencies jar from a Network location in Gradle 4.0?

Is there a way to download dependencies jar from a Network location in Gradle 4.0?
For example:
group 'com.hello'
version '1.0-SNAPSHOT'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile 'https://<hostname>:port/hello.jar' // can I do this?
}
Gradle has had this capability before 4.0, but it requires you to establish your own Maven or Ivy repository.
https://docs.gradle.org/current/userguide/dependency_management.html#sub:maven_repo
While I'm sure you could alternatively write some standard Groovy code to simply download a jar into the libs folder

Gradle not able to detect osdetector plugin

I am using OpenSSL for my Java GRPC project which uses gradle.
I read the documetation which mentions that we should make security settings as mentioned in this link.
I have included the osdetector plugin in the build.gradle file.
But when I build the project, gradle is not able to resolve the osdetector plugin and throwing error
> Failed to apply plugin [id 'com.google.protobuf']
> Plugin with id 'osdetector' not found.
My gradle file is as follows:
def neo4jVersion = "2.3.3"
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'idea'
apply plugin: 'com.google.osdetector'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.3'
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
}
}
protobuf {
protoc {
// The version of protoc must match protobuf-java. If you don't depend on
// protobuf-java directly, you will be transitively depending on the
// protobuf-java version that grpc depends on.
artifact = "com.google.protobuf:protoc:3.0.0-beta-2"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:0.12.0'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
generatedFilesBaseDir = "$projectDir/src/generated"
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'io.grpc:grpc-all:0.12.0'
compile "org.neo4j:neo4j:${neo4jVersion}"
compile "org.neo4j:neo4j-ogm-core:2.0.1"
compile "org.neo4j:neo4j-ogm-http-driver:2.0.1"
compile 'com.google.apis:google-api-services-storage:v1-rev71-1.22.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork14:' + osdetector.classifier
}
The compile dependency alone is getting resolved however.
I think I am missing something basic here. Please let me know the solution.
Updated
protobuf-gradle-plugin is not compatible with osdetector-gradle-plugin-1.4.0, since that version changed the name of the plugin. Swapping to version osdetector 1.2.1 should fix the problem.

Categories