简体   繁体   中英

Gradle and Lwjgl 3 Natives

I'm new to gradle and I'm trying to configure gradle with lwjgl 3 . Because I didn't found a repo where lwjgl3 is hosted i decided that everybody who use this project has to define the path to the lwjgl lib. I created a user.gradle file with contains the paths to the jar and to the natives.

My build.gradle looks like this at the moment.

apply plugin: 'java'
apply from: 'user.gradle'
apply plugin: 'application'

sourceCompatibility = 1.8
targetCompatibility = 1.8

mainClassName = "mp.Main"

println("LWJGL jar path is configured to: ${config.lwjgl3Jar}")
println("LWJGL natives path is configured to: ${config.lwjgl3Natives}")

repositories {
    mavenCentral()
    flatDir {
        dir config.lwjgl3Jar
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'net.java.dev.jna:jna:4.1.0'
    testCompile 'junit:junit:4.+'
    testCompile 'com.carrotsearch:junit-benchmarks:0.7.2'
    compile name: 'lwjgl'
}

tasks.withType(Test) {
    scanForTestClasses = false
    include "**/*Test.class" // whatever Ant pattern matches your test class files
}

sourceSets{
    main {
        java {
            srcDir 'src'
            exclude 'mp/graphics/gl/scene/Mesh.java'
            exclude 'test'
        }
    }

    test{
        java {
            srcDir 'src/test'
            exclude '**/UnsafeTest.java'
            exclude '**/DispatchTests/*'
            exclude '**/MemoryTest.java'
            exclude '**/SuperFastListTest.java'
            exclude '**/MatrixTest.java'
            exclude '**/SimulationTest.java'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

How to set the natives? I tried it different ways. Google didn't helped me out this time. All results are related to older versions of this lib and all are using repositories. Maybe I'm missing the forest for the trees in between. Any ideas?

Best regards!

PS: Not sure if it is important: We are using different IDE's like intelliJ and Eclipse on Windows, Linux, and Mac.

I have run into the same problem and wrote a plugin for handling the natives associated with Java jar files.

http://cjstehno.github.io/gradle-natives/

It will unpack them from the jar files so that you can use them and deploy them in your project.

I solved the problem for me. The problem for was that I didn't knew how to configure gradle to use the natives. Normally I set the the classpath in the run config. However:

The very simple solution how to set the classpath with gradle:

Apply the java plugin and use the function:

run {        
    systemProperty 'java.library.path', 'path to ur natives')
}

The simply run your application via gradle and it should work.

There were so many solutions by searching for "lwjgl gradle natives" that I didn't found the right one :-)

Hope the solution helps somebody.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM