1
\$\begingroup\$

I am currently using libgdx and IntelliJ to develop a real-time space 4x game. I ran into an issue, where I am trying to include lua scripts in my project (for the sake of allowing players to mod new behaviors into my game), and I ran into a slight issue.

In the past, using Eclipse, I had only ever needed to download pre-compiled binaries/.jar files, select them using Eclipse's built-in GUI, and import them into my project. I've literally never used a dependency management system like Gradle, and I don't really know how to add dependencies to my project. I've tried File -> Project Structure -> Libraries -> New Project Library, choosing Maven, and getting the following window:

enter image description here

Now, if I add this as a dependency to all of my projects, I get no errors:

enter image description here

Until it comes time to compile - the compiler is unable to resolve the imported LuaJ packages.

enter image description here

So, what is going on, how do I fix it? How do I, in a simple and straightforward way, add dependencies to my project (the project was generated using the default templates provided by the libgdx team)?

9:54:18 AM: Executing ':lwjgl3:org.origin.spacegame.lwjgl3.Lwjgl3Launcher.main()'...


> Task :core:compileJava FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.10.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
1 actionable task: 1 executed
C:\Users\djack\Desktop\LibGdx Games\Space Game\core\src\main\java\org\origin\spacegame\game\GameInstance.java:11: error: package org.luaj.vm2 does not exist
import org.luaj.vm2.Lua;
                   ^
C:\Users\djack\Desktop\LibGdx Games\Space Game\core\src\main\java\org\origin\spacegame\game\GameInstance.java:42: error: cannot find symbol
        Lua l;
        ^
  symbol:   class Lua
  location: class GameInstance
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.

BUILD FAILED in 947ms
9:54:19 AM: Execution finished ':lwjgl3:org.origin.spacegame.lwjgl3.Lwjgl3Launcher.main()'.

Steps to re-create the issue:

  1. Generate a new libgdx project using the libgdx project generator: libgdx.com/wiki/start/project-generation

  2. Import the project into IntelliJ.

  3. File -> Project Structure -> Libraries -> New Project Library

  4. Select "from maven."

  5. Type "luaj" and wait for the IDE to find a list of maven repos.

  6. Select com.diamondq.org.luaj:luaj-jse:3.0.2-SNAPSHOT

  7. Make sure transitive dependencies, sources, javadocs, and annotations are all selected.

  8. Click "OK" in the bottom right corner of the "Download Library from Maven Repository" window.

  9. Click "Apply" in the bottom right corner of the Project Structure window.

  10. Click "OK" in the bottom right corner of the Project Structure window.

  11. Import LuaJ into the application adapter in your core project.

  12. When an error appears, hover your mouse over the code and select "import into classpath."

  13. Once the error goes away, try to build/run your project.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Please edit to post your code (& where possible, error messages) as formatted text rather than screenshots. Some of the many reasons to post errors/code as text include making your question more searchable, and more accessible for folks using screen readers or translation software, so you get access to more experts who can help you. The {} icon above the editing window generally handles most code formatting. If you need more info you can check our formatting guide. \$\endgroup\$ Commented Oct 21, 2024 at 14:19
  • \$\begingroup\$ @Pikalek I edited the error in, but I really can't include an entire project. Use libgdx.com/wiki/start/project-generation to generate a new libgdx project in IntelliJ IDE (the plugins you include should be irrelevant). Then follow the steps mentioned in the post. Then try to build the project. That should re-create the issue. \$\endgroup\$ Commented Oct 21, 2024 at 15:02

1 Answer 1

1
\$\begingroup\$

I find it easiest to circumvent the UI and just add the dependency straight into build.gradle. You can find your build.gradle file in ROOT/PROJECT_TYPE/build.gradle where ROOT is the root of your project and PROJECT_TYPE is the type of LibGDX project (probably desktop or lwjgl3), e.g. MyGame/lwjgl3/build.gradle.

In this file, inside the dependencies section, add this line:

compile 'org.luaj:luaj-jse:3.0.1'

If you want to use the LuaJ library you found (it seems like an unofficial update or something) just add that instead:

compile 'com.diamondq.org.luaj:luaj-jse:3.0.2-SNAPSHOT'

The file should look something like this:

... stuff ...
dependencies {
    ... stuff ...
    compile 'org.luaj:luaj-jse:3.0.1'
}

Then you just have to refresh Gradle dependencies. Most IDE:s do this automatically but sometimes you have to do it manually, how to do this from the UI depends on the IDE but it should read something like "refresh Gradle dependencies".

\$\endgroup\$
1
  • \$\begingroup\$ compile was actually deprecated and removed, though I did end up finding a work-around - implementation fileTree(dir: '../libs', include: '*.jar', exclude: '*-sources*.jar') grabs and adds any libraries in the project's libs folder to the class-path. \$\endgroup\$ Commented Oct 23, 2024 at 4:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.