简体   繁体   English

Gradle和Lwjgl 3本地人

[英]Gradle and Lwjgl 3 Natives

I'm new to gradle and I'm trying to configure gradle with lwjgl 3 . 我是gradle的新手,正在尝试使用lwjgl 3配置gradle。 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. 因为我没有找到托管lwjgl3的存储库,所以我决定使用此项目的每个人都必须定义指向lwjgl lib的路径。 I created a user.gradle file with contains the paths to the jar and to the natives. 我创建了一个user.gradle文件,其中包含jar和本机的路径。

My build.gradle looks like this at the moment. 我的build.gradle现在看起来像这样。

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. Google这次没有帮我。 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. PS:不确定它是否重要:我们正在Windows,Linux和Mac上使用不同的IDE,例如intelliJ和Eclipse。

I have run into the same problem and wrote a plugin for handling the natives associated with Java jar files. 我遇到了同样的问题,并编写了一个插件来处理与Java jar文件关联的本机。

http://cjstehno.github.io/gradle-natives/ 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. 它将从jar文件中解压缩它们,以便您可以使用它们并将其部署到项目中。

I solved the problem for me. 我为我解决了这个问题。 The problem for was that I didn't knew how to configure gradle to use the natives. 问题是我不知道如何配置gradle以使用本机。 Normally I set the the classpath in the run config. 通常,我在运行配置中设置类路径。 However: 然而:

The very simple solution how to set the classpath with gradle: 一个非常简单的解决方案,如何使用gradle设置类路径:

Apply the java plugin and use the function: 应用Java插件并使用以下功能:

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

The simply run your application via gradle and it should work. 只需通过gradle运行您的应用程序即可。

There were so many solutions by searching for "lwjgl gradle natives" that I didn't found the right one :-) 通过搜索“ lwjgl gradle natives”有很多解决方案,我没有找到合适的解决方案:-)

Hope the solution helps somebody. 希望解决方案能帮助到别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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