我正在使用學習LibGDX遊戲開發,我試圖遵循Gradle的方式。在144頁的底部第4章,它說添加:來自LibGdx書籍的不良gradle代碼?
compile "com.badlogic.gdx:gdx-tools:$gdxVersion"
與此代碼段下面:
project(":desktop")
,我從本書的網站繼承下面張貼的的build.gradle。我在「-desktop」部分添加了代碼,但是我從Eclipse中得到了一個錯誤。
這是我的錯誤:
Could not find method compile() for arguments [com.badlogic.gdx:gdx-
tools:1.6.4] on [email protected]d80175.
我嶄新的品牌,以搖籃,沒有任何人知道,如果我想通過搖籃添加GDX-tools.jar中,我應該怎麼辦呢?
的build.gradle桌面項目:
apply plugin: "java"
sourceCompatibility = 1.6
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "com.packetpub.libgdx.canyonbunny.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
}
}
dist.dependsOn classes
eclipse {
project {
name = appName + "-desktop"
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
compile "com.badlogic.gdx:gdx-tools:$gdxVersion"
}
}
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
}
它應該是「com.badlogicgames.gdx:gdx-tools:$ gdxVersion」,請參閱:https://github.com/libgdx/libgdx/wiki/Dependency-management-with-Gradle#tools-gradle – Xoppa
我再也沒有遇到這個錯誤,但是當我進入Gradle-> Refresh Dependencies時,gdx-tools jar不會出現在我的Gradle Dependencies文件夾中。我仍然做錯了嗎? – smuggledPancakes
你有一個root build.gradle和不同的gradle文件,用於每個子項目(桌面,android,ios等),對不對? – yigiter