How to build a project using gradle

My ANT Project suddenly converted into Gradle for no reason; however, I do want to use gradle as many libraries do not have .JARs. I need help with the build.gradle.

image

My files do not show up; only the build scripts. How can I get those to show up? How can I add my libraries using gradle? I know you have to use github, but I don’t know how to write the actual file? Can somebody help me by giving me a sample of what to do? My directories look like this:
src → folder1 → Mainfile

Here is my build.gradle: (I tried using the fps-demo from the jMonkeyEngine store’s build)

Somebody pls help!

Just remove the Gradle files… if you want to stick to ANT. That is probably where the IDE figures you have an Gradle project…

Edit: Sorry I read wrong, you want to stick to Gradle

Add src → folder1 to the build.gradle (sourceSets)

And the only reason that’s needed is because of the non-standard layout that the game template sets up.

Ok, but now I have another issue.

I can now access my source project and everything inside, but when I add dependencies, all the imports crash.

Here is my build.gradle:

plugins {
    id 'application'
    id 'java'
    id "io.github.0ffz.github-packages" version "1.2.1"
}

group 'MarsGame'


mainClassName = 'MarsGame.MainLoop'
if (!hasProperty('mainClass')) {
    ext.mainClass = mainClassName
}

repositories {
    mavenCentral()
        maven { url 'https://jitpack.io' }
    maven githubPackage.invoke("riccardobl")
    maven githubPackage.invoke("jmePhonon")
    maven githubPackage.invoke("jMonkeyEngine-Contributions")
}

project.ext {
    jmeVer = "3.3.0-stable"
}

dependencies {
    implementation 'com.github.jMonkeyEngine-Contributions.Lemur:lemur:master-SNAPSHOT'
    implementation 'wf.frk:jme3-bullet-vhacd:1.0.5'
    implementation 'wf.frk:jme-effekseer-native:0.3'
    implementation(group: 'com.jme3.phonon', name: 'jme_phonon', version: '0.3.7', ext: 'jar', classifier: '')
    implementation "wf.frk:jme3-bullet-vhacd:1.0.5"
    implementation "wf.frk:jme_f3b:0.92"
    implementation "org.jmonkeyengine:jme3-core:$jmeVer"
    implementation "org.jmonkeyengine:jme3-desktop:$jmeVer"
    implementation "org.jmonkeyengine:jme3-effects:$jmeVer"
    implementation "org.jmonkeyengine:jme3-plugins:$jmeVer"
    // choose lwjgl or 3
    implementation "org.jmonkeyengine:jme3-lwjgl:$jmeVer"
    // bullet physics
    implementation "org.jmonkeyengine:jme3-bullet:$jmeVer"
    implementation "org.jmonkeyengine:jme3-bullet-native:$jmeVer"
    
	
    // post processing effects
    implementation 'com.github.polincdev:ShaderBlowEx:master-SNAPSHOT'
    
}

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDirs 'assets'
            exclude 'Converted/**'
        }
    }
}

jar {
	manifest {
	    attributes 'Main-Class': mainClassName
    }
	from {
        configurations.runtimeClasspath.filter{ it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
    }
    exclude("META-INF/*")
}

here are my imports before I add the line "
com.github.jMonkeyEngine-Contributions:Lemur:Tag
" to dependencies


I want to add the library com.simsilica but it cannot find it. So when I do add that dependency, here is what happens:


All of the libraries – native jme3 and the phonon ones cannot be imported. This is really weird. Somebody please help!

I’m sure your IDE or command line gradle build gives an error. You should post that. Otherwise it is really difficult to help.


^^ this is the gradle error i got


^^ command line error

I think you are adding the dependency wrong… You can try JitPack
https://jitpack.io/p/jMonkeyEngine-Contributions/lemur

Why do you add the lemur dependencies in such a strange way?

Just put jcenter() in the repositories and then reference the public release directly:
“com.simsilica:lemur:1.15.0”
com.simsilica:lemur-proto:1.12.0"

…and so on.

Yeah, this Github packages thing is new to me. I guess it is plausible.

I tend to google “package maven” to find whatever dependency I need from Maven Central. JCenter as secondary, but it is apparently taken out at some point (Sunset on May 1st: Bintray, JCenter).

Jitpack is my third source. It is very handy if one wants to fork a project on Github and use it as a dependency. How to explain it… Well one can upload anything there and reference it through Gradle.

1 Like

JFrog says they will keep jcenter around now. How long is anyone’s guess but ‘indefinitely’ is long enough for now.

Everyone’s repository list should be:
mavenLocal()
mavenCentral()
jcenter()
…in that order. Add whatever else to the bottom only as needed.

2 Likes