How to add dependency in Gluon Project - java

I have my custom jar file suppose to be added in the classpath of my Gluon project, but I couldn't find any facility in Netbeans that allows you to add your custom jars. Can someone guide me on how to do it?
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b9'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
}
mainClassName = 'com.rameses.Main'
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
}
}

Though I do not use Netbeans or the plugin you have mentioned, but since it is a gradle project, you can add the custom jars to your classpath by adding the following code in your build.gradle file.
dependencies {
compile files('libs/custom.jar')
}
where,
libs/custom.jar is the relative path of the jar w.r.t to the gradle file.

Related

Understanding buildscript

How to understand following build.gradle script:
buildscript
{
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
According to my understanding repositories{} defines dependencies{} locations.
I see that dependencies wrapped inside of buildscript defines tomcat plugin. But what is idea to do so in such strange way?
Whole script:
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'eclipse-wtp'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
dependencies {
def tomcatVersion = '8.0.46'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
api 'org.apache.commons:commons-math3:3.6.1'
}
tomcat {
httpPort = 8080
enableSSL = true
contextPath = '/library-spring'
}
Nowadays almost all plugins for Gradle are published to the Gradle Plugin Portal, so Gradle knows how to resolve them and you can simply use the plugins block to define them in your build script:
plugins {
id 'com.bmuschko.tomcat' version '2.5'
}
In earlier days of Gradle, plugins could only be distributed in the same way as any other library, e.g. using a public Maven repository like Maven Central or Bintray. This way they could be resolved in the same way as other libraries, using the dependencies block to define what to resolve and using the repositories block to define where to resolve.
The problem of using the regular repositories and dependencies blocks is, that those dependencies are loaded when the build script gets evaluated. But to evaluate the build script, the plugin libraries are required to be on the classpath.
For this reason, the buildscript block was introduced to load all the dependencies before evaluating the actual build script. This is also the reason why the buildscript block should always go first in a build script:
buildscript {
repositories {
// where to resolve dependencies of your build script
}
dependencies {
// what dependencies to resolve for your build script
}
}
repositories {
// where to resolve dependencies of your project code
}
dependencies {
// what dependencies to resolve for your project code
}

ERROR: Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8

I have problem with build project in android-studio from https://github.com/Samsung/microbit.
I imported repository by git, but while build gradle project from in android-studio I have error:
ERROR: Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71.
I am not sure how I can change version 1.2.72 to other version.
Edit:
Solution:
I added mavenCentral() to
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
google()
}
}
I think there is no need to use that as you can use kotlin-stdlib directly.
Try this:
In your app level build.gradle file, under dependencies section:
dependencies{
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.41"
}

libGdx and facebook

I'm testing facebook login with libgdx project. In my project-level build.gradle file, I added the gdx-facebook dependency from here
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
......
......
compile "de.tomgrill.gdxfacebook:gdx-facebook-android:1.4.1"
}
}
and added the following dependency in the Module:android build.gradle file.
dependencies {
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}
There is no error in such condition. But when I remove tomgrill dependency from project-build.gradle file, android studio show me the following alert and the project cannot run.
Gradle project sync failed. Basic functionality(e.g. editing,
debugging) will not work properly.
Why facebook dependency does not work without tomgrill gdx-facebook extension? What the problem is?
Artifact facebook-android-sdk available in mavenCentral repository so you've to add mavenCentral() in your project repositories list in root build.gradle file.
By default, In LibGDX projects mavenCentral() is in repo list.
Some transitive dependency in your project, Internally facebook-android-sdk using many support library like annotations, customtabs, appcompat-v7, support-v4 and more..
These support libraries are available on Google's Maven repository so you need to include Google's Maven repository in your top-level build.gradle file :
allprojects {
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
// An alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}

Android Studio: JavaSE app

I am working on a project which should run on Android as well as on desktop (JavaSE). For this purpose I've separated it into 3 java modules:
AndroidApp
CommonCore
DesktopApp
Why I am using Android Studio (AS) is obvious. I've got almost everything to work but the "Run" button for the JavaSE module. The problem is simple: incomplete classpath. The module compiles, but it doesn't run. When I build it into JAR it runs fine. JAR includes all required dependencies. The only problem is the damn "Run" button when used on the JavaSE module.
top-level build.gradle: (pretty much generated by AS)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
CommonCore build.gradle:
apply plugin: 'java-library'
targetCompatibility="1.8"
sourceCompatibility="1.8"
dependencies {
api 'org.nanohttpd:nanohttpd:2.3.1'
api 'com.google.code.gson:gson:2.8.1'
api 'org.apache.commons:commons-text:1.1'
api files('src/main/resources')
}
DesktopApp build.gradle:
apply plugin: 'java'
targetCompatibility="1.8"
sourceCompatibility="1.8"
dependencies {
implementation project(':CommonCore')
implementation 'org.xerial:sqlite-jdbc:3.21.0.1'
}
jar {
manifest {
attributes 'Main-Class': 'myproject.Main'
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
AndroidApp build.gradle: (skipped the actual android settings to keep it short)
apply plugin: 'com.android.application'
dependencies {
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation project(':CommonCore')
}
android { ... }
When I run it I get:
Exception in thread "main" java.lang.NoClassDefFoundError: fi/iki/elonen/NanoHTTPD
Apparently JVM could not find the dependency 'org.nanohttpd:nanohttpd:2.3.1' from CommonCore. After examining classpath I see:
/Applications/Android Studio.app/Contents/jre/jdk/<a ton of unused JARs>
/Users/bamboo/AndroidStudioProjects/MyProject/DesktopApp/build/classes/java/main
/Users/bamboo/AndroidStudioProjects/MyProject/CommonCore/build/classes/java/main
Missing entries for Gradle managed dependencies.
What have I done wrong? AS must see them because autocomplete works well.
Place the dependency inside runtime() in the gradle, for example:
dependencies {
runtime(
[group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'],
)
}
Reference
One way to fix it is to use NetBeans with Gradle plugin for JavaSE development.

Neokree Navigation drawer: Gradle DSL method not found: 'compile()'

I am trying to Set up a Navigation Drawer by Neokree https://github.com/neokree/MaterialNavigationDrawer on Android Studio with no success.
After adding this to my gradle -> build.gradle file
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
And then i get this Error Saying "Gradle project Sync Failed" and this below
Error:(27, 0) Gradle DSL method not found: 'compile()'
Possible causes: The project 'MaterialNavigationDrawer' may be using a version of Gradle that does not contain the method.
Gradle settings The build file may be missing a Gradle plugin.
Apply Gradle plugin.
This is my gradle folder -> Build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
I know am doing something wrong for sure, and I can't seem to figure it out.
There is a great library called MaterialDrawer. You can integrate this library in less than 5 minutes in your project (read its README.md and Wiki - a lot of informations is available there!).
Good luck!

Categories