Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (727)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (796)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Gradle - How to isolate concurrent runs?  (Read 450 times)
0 Members and 1 Guest are viewing this topic.
Offline Ecumene

JGO Kernel


Medals: 180
Projects: 3
Exp: 8 years


I did not hit her! I did not!


« Posted 2017-04-15 18:19:36 »

I've run into some problems this week with my game, I noticed the game would work when it was played on another computer and someone else joined, but me running two games (server+client and a second client) on my computer caused JVM crashes, and class not found errors.

After some debugging and very long stares at hs_err_pidXXX logs (y'all know the struggle) I found out the errors were caused by classes in the gradle build folder being changed + deleted when I build the game a second time.. Closing one game deleted the files for the server, and when it went to load the classes for the disconnect event the server crashed.

I sifted the internet for gradle task properties of the "application" plugin's "run" task, to maybe run the program in a second build folder, but no luck..

I'm considering changing my run task to build the game into a jar, and run that instead.. But I havent written gradle scripts before and that seems like a pain.

If anyone has some ideas on how to isolate gradle runs that would be awesome!

Offline abcdef
« Reply #1 - Posted 2017-05-18 13:02:54 »

The run task depends on the classes task which depends on processResources and compileJava. This should not rebuild every time as it should cache things and know it has run things before, sounds like it is not happening and you are actually rebuilding the class files between runs so one run removes the classes from the other. I'd investigate more why this happens
Offline matt_p
« Reply #2 - Posted 2017-05-19 07:33:22 »

here, have my gradle script template to create a jar - calling it with gradle createJar

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
apply plugin: 'maven'
apply plugin: 'java'

def mainClassName = 'com.mainclasspackage.Main'

repositories {
   mavenLocal()
   mavenCentral()
}


dependencies {
   // compile '<group>:<name>:<version>'
   // ... more here if necessary
}

task copyRuntimeLibs(type: Copy) {
    into "build/libs/lib"
    from configurations.runtime
}

task createJar(type: Jar){
   
   dependsOn build
   dependsOn compileJava
   dependsOn copyRuntimeLibs
   
   from 'build/classes/main'
   
   manifest {
        attributes(
         "Main-Class": mainClassName,
         "Class-Path": ". " + configurations.compile.collect { 'lib/' + it.getName() }.join(' ')
      )
    }
}


note: replace the dependencies (if you have any)
this setup copies the dependency jars next to the resulting jar inside a lib folder and sets the class path accordingly in the generated jar

the generated jar lands in build/lib

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline abcdef
« Reply #3 - Posted 2017-05-19 13:02:13 »

In your jar task you can add

into('lib'){
        from configurations.runtime
        include '*.jar'
}

To save depending on a custom copy task
Offline Ecumene

JGO Kernel


Medals: 180
Projects: 3
Exp: 8 years


I did not hit her! I did not!


« Reply #4 - Posted 2017-05-20 21:27:11 »

The run task depends on the classes task which depends on processResources and compileJava. This should not rebuild every time as it should cache things and know it has run things before, sounds like it is not happening and you are actually rebuilding the class files between runs so one run removes the classes from the other.

Although it does have to rebuild, because one game is running the server and the other isn't.. Half of the codebase (server code) in one instance of the game isnt even loaded, which causes differences in classes, and some confusion in the JVM in general as the two instances share the same classes folder (I think)

I'd love to investigate more but I dont know where to take it, past sifting the .class files finding client-only code being run on the server+client instance.

Since April I've done two things to fix this,
1. A separate clientRun task that builds in a different folder than run, but to no avail. (Still crashes with the same errors)
2. Copied the entire root folder and ran the game concurrently, this worked but copying the game to test multiplayer is very tedious!

If anyone has more info on why these crashes are happening I'd be grateful! And thanks guys for the jar code, but running the game through a built jar each time is more of an afterthought that wouldn't be convenient.

Pages: [1]
  ignore  |  Print  
 
 

 
Archive (294 views)
2017-04-27 17:45:51

buddyBro (483 views)
2017-04-05 03:38:00

CopyableCougar4 (927 views)
2017-03-24 15:39:42

theagentd (941 views)
2017-03-24 15:32:08

Rule (952 views)
2017-03-19 12:43:22

Rule (921 views)
2017-03-19 12:42:17

Rule (922 views)
2017-03-19 12:36:21

theagentd (984 views)
2017-03-16 05:07:07

theagentd (897 views)
2017-03-15 22:37:06

theagentd (693 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!