Fat jar created by simulateJava doesn't have all dependencies

I’m working on a simulation program separate from WPILib stuff. However, it will sometimes be beneficial to utilize the simulateJava feature of a 2019 WPI project.

When running ./gradlew wpi:simulateJava (my wpi project is in a submodule), it looks like it is successful:

Program Output logfile: /home/josh/Programming/First1444/Simulation/robot2019-sim/wpi/build/stdout/simulateJava.log
Simulation Launched! PID: 23425 (written to /home/josh/Programming/First1444/Simulation/robot2019-sim/wpi/build/pids/simulateJava.pid)

However, if I dig deeper, the PID isn’t running. When running wpi/build/gradlerio_simulateJava.sh I get this error:

Error: Unable to initialize main class com.first1444.frc.robot2019.Main
Caused by: java.lang.NoClassDefFoundError: com/first1444/sim/api/RunnableCreator

Now at first I thought. Hmm, probably just a simple problem with my jar configuration. But that’s not the case. Here’s a simple layout of how my project is structured:

robo-sim

  • submodule: “api”
  • submodule: “wpi”
    • Depends on “api”

robo2019-sim

  • submodule: “core”
    • Depends on robo-sim:api
  • submodule: “wpi” (This is the submodule which I’m running simulateJava from)
    • Depends on “core”
    • Depends on robo-sim:wpi

So the problem is that everything from robo-sim:api (such as RunnableCreator) fails to be put into the classpath of the jar but classes in robo-sim:wpi are in correctly and of course classes from “core” work correctly.

This could be a problem in my robo-sim library, but I managed to create a fat jar in a libgdx program that had dependencies correct.

I’m pretty lost here. I know that my gradle configuration is probably one of the most uncommon ones that involves WPILib but any help is appreciated.

I don’t think this problem is kotlin related. I’m using a mix of Java and Kotlin.

robo-sim: https://github.com/frc1444/robo-sim
robo2019-sim: https://github.com/frc1444/robot2019-sim
I will be creating a thread before kickoff about this simulation. It’s coming along well but messing with gradle for an entire day is not fun.

I’m running Ubuntu 19.04 and I’m using Java 12. I could try switching to Java 11, but I’m able to run simulateJava without errors on other traditional robot programs.

This was an issue with the 2019 templates. For 2020, this has been fixed, but can be fixed in 2019 projects by changing

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

to

from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

That should fix it. Note I’m not sure how this interacts with api vs implementation in gradle, that is all very confusing to me. So you might need implementationClasspath if thats a thing, not fully sure.

2 Likes

THANK YOU. I spent way too much time trying to figure out what was causing this.

I didn’t have to change anything else except that.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.