Simsilica libraries moving to gradle

Kind of starting this topic to serve as a pre-announcement and let folks who build from source know why stuff is moving around in some cases.

So far, I’ve converted:
Lemur
LemurProto
LemurProps
zay-es
Zay-ES-Net
Pager
SimFX
SimMath
SiO2

This is all in prep for getting my libraries up on jcenter() for easy inclusion in other gradle/maven based projects. (There is the submarine announcement that JME jars will be showing up in jcenter() soon, too, if everything goes well… starting with alpha2 I guess.)

Next will be converting stuff in the github/simsilica project like IsoSurface, SimMath, SimArboreal, SimFX, etc…

If anyone is interested, I could provide an “n easy steps to building a JME project with gradle”… it would be command line centric as I’m ‘old school’.

Anyway, I’ll post back as I get the other projects configured.

Nice thing, if you want to build Lemur or Zay-ES from source, just checkout the projects and run:

gradlew build

You don’t even have to install gradle… it will download it for you.

You can then find the relevant jars in the projects’ build/libs directory.

10 Likes

Note: at least for a long while, I’ll still publish releases the regular way I have been, also.

:raised_hand:

Also I don’t suppose you could point me in the direction of some literature explaining how to write Gradle build scripts?

P.S. Usually prefer the command line myself…

nha… fashion did a whole revolution because youngster are all crazy about command line dude… you’re not old anymore when using command line… you’re right into the hype…

They say trends are cyclical, I’m sure breeches are about to make a big comeback :stuck_out_tongue:

It’s really simple, actually. I’ll describe it in terms of getting a JME app up and running.

Step 1: have gradle installed so that you can run gradle from the command line.

Step 2: make a directory somewhere that you want your project. We’ll call it ‘pie’ for the sake of this discussion.

md pie

Step 3: make the src directories and a .java file in it. I’ll use a sort of example similar to the one the SDK makes.

cd pie
md src
md src/main
md src/main/java
md src/main/java/mygame

Now create the Main.java file in there:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.math.ColorRGBA;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

public class Main extends SimpleApplication {

    public static void main( String... args ) {
        Main main = new Main();
        main.start();
    }

    @Override
    public void simpleInitApp() {

        Box box = new Box(1, 1, 1);
        Geometry geom = new Geometry("My Box", box);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);

        rootNode.attachChild(geom);
    }
}

So far… that’s pretty much how you’d start any Java project from the command line.

Now… let’s create the gradle build file.

Step 4: Create the gadle build file (from the pie directory)

gradle init

Step 5: Edit the build file
It starts off looking like this:

/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'PSpeed' at '1/28/16 5:04 PM' with Gradle 2.10
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.10/userguide/tutorial_java_projects.html
 */

/*
// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.13'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
}
*/

First thing you’ll want to do is uncomment all of that.

// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.13'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
}

Now, normally that would be enough to start declaring JME dependencies but right now JME is not on jcenter so we have to add the bintray repo:
maven { url “http://dl.bintray.com/jmonkeyengine/org.jmonkeyengine” }

Also, for the app to compile we will need to add a compile dependency on jme core.
compile “org.jmonkeyengine:jme3-core:3.1.+”

And to actually run you will need the desktop and lwjgl dependencies but they are only runtime dependencies:
runtime “org.jmonkeyengine:jme3-desktop:3.1.+”
runtime “org.jmonkeyengine:jme3-lwjgl:3.1.+”

Now, you should be able to build with the build file like this:

apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    jcenter()
    
    maven { url "http://dl.bintray.com/jmonkeyengine/org.jmonkeyengine" }
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile "org.jmonkeyengine:jme3-core:3.1.+"
    runtime "org.jmonkeyengine:jme3-desktop:3.1.+"
    runtime "org.jmonkeyengine:jme3-lwjgl:3.1.+"
}

Note: the + at the end of the versions is because currently what’s up is a milestone build and this will give you the latest 3.1 whatever that happens to be.

“That’s great, Paul… but how do I run it.”

Well, I’m glad you asked. If you add two lines to the gradle file you can use the app plugin.

Load the plugin with:
apply plugin: ‘application’

…and that plugin requires that you declare a main class:
mainClassName = ‘mygame.Main’

Now the build file looks like this:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'mygame.Main'

// In this section you declare where to find the dependencies of your project
repositories {
    jcenter()
    
    maven { url "http://dl.bintray.com/jmonkeyengine/org.jmonkeyengine" }
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile "org.jmonkeyengine:jme3-core:3.1.+"
    runtime "org.jmonkeyengine:jme3-desktop:3.1.+"
    runtime "org.jmonkeyengine:jme3-lwjgl:3.1.+"
}

And you can simply use ‘gradle run’ to build and run your app.

7 Likes

Awesome, thank you for that. Quick question, how do I add locally stored dependencies? Do I add a local folder as a repository, or just reference the library directly in the dependency section?

Depends on what kind of locally stored dependency. The best way is to use the real maven reference if you have it and/or put mavenLocal() in your repo section and mvn install the deps if you are building some public project from source that uses maven.

Else, yeah, gradle makes it pretty easy to include all of the jars in a lib directory or something. I don’t have the gradle script handy.

Added:
Pager
SimFX
SimMath
SiO2

to the converted list. This may be all I do for a bit as these are the ones I need for my current project. (And there are a handful of unpublished someday-open-source libraries that I’m also managing this way at the moment.)

At some point, I centralize the common bits into a central gradle file and save myself a bunch of trouble.

Note: my example above doesn’t cover the assets directory or jar. I will add to it later as I get the ‘best’ way worked out myself.

1 Like

Some of the lib are avaiable via jitpack.io, eg instruction for Pager

repositories {
	...
	maven { url "https://jitpack.io" }
}
dependencies {
       compile 'com.github.Simsilica:Pager:-SNAPSHOT'
}

But some libs aren’t buildable by jitpack like Lemur (missing apply plugin maven or maven-publish).

jitpack must be confused. The root Lemur build injects the maven plugin into all of the lemur build.gradle files.

Eh… Sorry for being a lazy ass. I want Zay-Es in my gradle project. Use jitpack link from @david_bernard_31 or should we setup a bintray for simsilica’s libs ?

https://jitpack.io/com/github/jMonkeyEngine-Contributions/zay-es/v1.1.1/build.log

ERROR:
No build file found. Looking for Gradle/Maven/Sbt/Lein build file in the root of the project

2016-01-31T12:28:30.873021666Z

Seem like Zay-es also can not be built?

Well, that version 1.1.1 never had a build.gradle file, I guess. Not sure how david has all of this setup.

I will be doing this. I’m still reading about it in my ‘spare time’. I wont official libs on jcenter so that users don’t have to add weird repos to their gradle builds.

Just a note for those using david’s version of my libs, the group names will have to change also when you switch to the official ones later. No big deal… just something to be aware of.