Well its done so you can run your game…
In regular JME ant based project it only builds assets.jar when i do Build
or Clean and Build
not every time i run the game .
You just said it does it every time that you add a new model…? Normally gradle should not rebuild a jar when the source files don’t change?
Yes when adding new model.
But why it does not happen in regular ant based jme project ?
So whats the issue? Waiting 20 seconds when you add a new model is so bad? It doesn’t happen in the ANT project because it uses the compiled classes in “build/classes” and the assets directory directly and only builds jars on deployment.
It is not 20 seconds, it is more than 10 minutes.
Can we set it on gradle too ?
10 minutes? Do you code on a phone from 1992?
Nothing keeps you from changing the build script or using the SDK ANT project. But thats not how gradle works.
I have the same Problem there.
The thing is if you have many assets it still redoes any Single one.
I could reduce the time by 3 mins by removing the Old ogre files. Those Textures were Huge.
So the actual question is: how can i set it so that the assets:jar Task is only run on dist?
That would really help as the processResources Task seems to do what ant in the SDK was doing
“Old ogre files?” In the gradle project you’re not supposed to keep your input files in the assets folder. Asset management and conversion is a SDK feature. Here you’re only supposed to have the stuff you actually need in the game in the assets folder. I don’t know how you’re supposed to create j3o files for your project but I guess at some point there will be a tool for that or whatnot.
Regardless of how you proceed, step 1 would be to add some filtering to stop sucking in the things you don’t want in assets.jar.
Can you please help with this filtering step ?
I tried to add following task myPack but it failed to run. (I copied it from some one else build file !)
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'
mainClassName='com.overthemoon.tnw.main.Main'
repositories {
//Uncomment this if you install local dependencies.
mavenLocal()
//This is where jme3 dependencies are stored.
jcenter()
//Uncomment this if you use external dependencies
mavenCentral()
//Uncomment this if you use jme3-niftygui
//maven{url 'http://nifty-gui.sourceforge.net/nifty-maven-repo'}
}
ext.jmeVersion = '[3.2,)'
project(":assets") {
apply plugin: "java"
buildDir = rootProject.file("build/assets")
sourceSets {
main {
resources {
srcDir '.'
}
}
}
}
task myPack(type: Jar) {
from 'assets'
exclude('**/*.blend','**/*.blend1','**/*.db','**/*.url','**/*.mtl','**/*.xml','**/*.scene','**/*.dae','**/*.bvh','**/*.mb','**/*.j3odata','**/*.max','**/*.txt','**/*.zip','**/*.rar','**/*.fbx','**/*.obj')
baseName 'assets'
}
dependencies {
compile "org.jmonkeyengine:jme3-core:$jmeVersion"
compile "org.jmonkeyengine:jme3-desktop:$jmeVersion"
compile "org.jmonkeyengine:jme3-lwjgl:$jmeVersion"
//runtime project(':assets')
runtime ":myPack"
}
task wrapper(type: Wrapper) {
}
task createDirs << {
def pkg = 'mygame'
def dirs = [
file("./src/main/java/$pkg"),
file("./src/main/resources"),
file("./assets/Interface"),
file("./assets/MatDefs"),
file("./assets/Materials"),
file("./assets/Models"),
file("./assets/Scenes"),
file("./assets/Shaders"),
file("./assets/Sounds"),
file("./assets/Textures"),
]
dirs.each {
if( !it.exists() ) {
println "Creating " + it
it.mkdirs()
}
if( it.listFiles().length == 0 ) {
def stub = new File(it, 'removeme.txt')
println "Creating stub file to allow git checkin, file:$stub"
stub.text = "Remove me when there are files here."
}
}
}
this is runtime error :
* What went wrong:
Execution failed for task ':run'.
> Could not resolve all dependencies for configuration ':runtime'.
> Could not find :myPack:.
Searched in the following locations:
file:/home/idea/.m2/repository//myPack//myPack-.pom
file:/home/idea/.m2/repository//myPack//myPack-.jar
https://jcenter.bintray.com//myPack//myPack-.pom
https://jcenter.bintray.com//myPack//myPack-.jar
https://repo1.maven.org/maven2//myPack//myPack-.pom
https://repo1.maven.org/maven2//myPack//myPack-.jar
Required by:
:MMORPG:unspecified
Ah… I know this is a pretty noob question.
I think there is a way to modify the sourceSets.main.resources itself but you might also try adding a processResources to your project(":assets") like:
processResources {
exclude(‘path/or/file/*.someExtension’)
}
…using gradle’s standard file processing. I remember doing it in my sourceSets before but I’d have to dig.
Silly me… how to do it is right at the top of this page:
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSet.html
It’s doing it for Java but the same should work for resources. So right at the same level as your srcDir you should be able to add includes, excludes, etc… just like any other filespec in gradle.
Thanks it worked. Now it takes less than 5 minutes to build and asset file size is 700 mb. (main problem is texture files)
It is yet too much time, i may need to build each model as separate jar ?
But not know how to do it yet, I will google it.
Thanks for your ALL helps.
Sounds like you need to find a better jpg exporter…
So i decided to give it a try. Here as an example i want to build Textures
and Models
folder as separate jars. (This is just an example)
I changed my build.gradle to :
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'
mainClassName='com.overthemoon.tnw.main.Main'
repositories {
//Uncomment this if you install local dependencies.
mavenLocal()
//This is where jme3 dependencies are stored.
jcenter()
//Uncomment this if you use external dependencies
mavenCentral()
//Uncomment this if you use jme3-niftygui
//maven{url 'http://nifty-gui.sourceforge.net/nifty-maven-repo'}
}
ext.jmeVersion = '[3.2,)'
project(":assets") {
apply plugin: "java"
//Set a Jar task to all of SourceSets.
sourceSets.all { set ->
def jarTask = task("${set.name}Jar", type: Jar) {
baseName = baseName + "-$set.name"
from set.output
}
artifacts { archives jarTask }
}
//Print Main Sourceset Properties
task sourceSetProperties << {
sourceSets {
main {
println "java.srcDirs = ${java.srcDirs}"
println "resources.srcDirs = ${resources.srcDirs}"
println "java.files = ${java.files.name}"
println "allJava.files = ${allJava.files.name}"
println "resources.files = ${resources.files.name}"
println "allSource.files = ${allSource.files.name}"
println "output.classesDir = ${output.classesDir}"
println "output.resourcesDir = ${output.resourcesDir}"
println "output.files = ${output.files}"
}
}
}
buildDir = rootProject.file("build/assets")
// SourceSet's Configuration
sourceSets {
Models
Textures
main{
// java {
// srcDir 'src/Models'
// srcDir 'src/Textures'
// }
resources {
srcDir './Models'
srcDir './Textures'
//exclude('**/*.blend','**/*.blend1','**/*.blend2','**/*.blend*','**/*.db','**/*.url','**/*.mtl','**/*.xml','**/*.scene','**/*.dae','**/*.bvh','**/*.mb','**/*.j3odata','**/*.max','**/*.txt','**/*.zip','**/*.rar','**/*.fbx','**/*.FBX','**/*.j3o','**/*.obj')
}
}
}
// JAR Task Configuration, define output the directories that make up the file.
jar {
from sourceSets.Models.output
from sourceSets.Textures.output
}
// Compile, Test and Run dependencies
dependencies {
compile sourceSets.Textures.output
compile sourceSets.Models.output
}
}
dependencies {
compile "org.jmonkeyengine:jme3-core:$jmeVersion"
compile "org.jmonkeyengine:jme3-desktop:$jmeVersion"
compile "org.jmonkeyengine:jme3-lwjgl:$jmeVersion"
runtime project(':assets')
}
task wrapper(type: Wrapper) {
}
task createDirs << {
def pkg = 'mygame'
def dirs = [
file("./src/main/java/$pkg"),
file("./src/main/resources"),
file("./assets/Interface"),
file("./assets/MatDefs"),
file("./assets/Materials"),
file("./assets/Models"),
file("./assets/Scenes"),
file("./assets/Shaders"),
file("./assets/Sounds"),
file("./assets/Textures"),
]
dirs.each {
if( !it.exists() ) {
println "Creating " + it
it.mkdirs()
}
if( it.listFiles().length == 0 ) {
def stub = new File(it, 'removeme.txt')
println "Creating stub file to allow git checkin, file:$stub"
stub.text = "Remove me when there are files here."
}
}
}
In build/assets/libs
folder now i have
but assets-Textures.jar
, assets-Models.jar
are empty with only MANIFEST.MF
inside them.
I followed this tutorial : Gradle SourceSets Example - Java Code Geeks
Can you please help .
Easy way… if you don’t want assets.jar then don’t use assets.jar.
Just shove your assets in some directory and add it as an asset path during your app startup.
Yes. I removed assets project from gradle build and added asset folder to class path by adding runtime files('src/main/resources/assets')
to dependencies
.
Thanks.
Regarding previous approach about separating asset jar for each model, I yet need to find solution. Because i do want to distribute my models in separate jars instead of one huge assets.jar so in client side i can easily fetch new models using getdown.
If anyone has a working gradle build file for this can you please share
Just make different subprojects and depend on them like the assets project.
That’s one way. Using this way we should manually create subproject for each model.
But can we use some other ways to generate jars dynamically !?
As an example see :
So using gradle script can we do something like, iterating over all sub folders of Models
directory (Character1,Character2,...
) and create .jar for each sub folder. And do it for other categories too, Textures,Sounds,...
?
Edit : Never mind, i think i found a work around with creating archives task.