[Solved] Error with CommandSpec and Optional

Hey guys, I’ve wanted to try out Sponge as soon as I heard that the JAR-File is available :smiley:
So I followed the Docs to create my first Command with the CommandSpec-Builder but now I have an error with registering the command…

My Class:

Code

So the line game.getCommandDispatcher().register(this, sp, "hallo", "hi"); is underlined red and eclipse is giving me the error: The type com.google.common.base.Function cannot be resolved. It is indirectly referenced from required .class files
Sometimes it’s not Function but Optional and the import isn’t available :confused:
My Sponge-Version is 439, I hope you guys understand my problem apart from my bad english(I guess :smiley:)

The required dependencies are not in your classpath, make sure set up the gradle dependencies correctly.

How do I do that? I’ve only imported the JAR-File like the Spigot/Bukkit-JAR…

Don’t import the jar file, that’s not how you’re supposed to do it. Read the instructions on the docs

https://docs.spongepowered.org/en/plugin/basics/workspace/dependencies.html

Ok, I did it now. I’m kinda new to Maven, cause I never used it before :smiley:
But one last question: How do I export the plugin, just normal? And about the folder hierarchy… should my main class go there: Picture ?

That is correct, that would be where you put your main class. To build your plugin, just run mvn clean install in the root directory of your plugin, and the newly built jar will be in the target folder

Where did I need to run it? In a Maven terminal or something like that? Sorry for those dumb questions, but as I said before

:wink:

The best way to do it (for future usability) would be to add Maven to your PATH: Here is a tutorial for Windows, Mac, and Linux (about half-way down the page). Then, just cd to your plugin’s root directory (in the command line/terminal) and run mvn clean install

Ah ok now I’ve managed to compile it with maven and get the final jar :smiley:
But if I extract the jar, there’s no difference in the folders between the normal exported jar…
So I guess, I needed to use maven, 'cause of the sponge-jar? ;D

Why are you extracting the jar? You should just be putting it in the mods folder of your server… Or am I misunderstanding?

I extracted it to see the difference between maven compiling and just exporting the jar xD I know where to put the jar, that was just something that I wanted to know ;D But yeah there’s no big difference if you do that.

What I wanna say is, theres no difference between exporting the jar in eclipse as a jar file and compiling it with maven…

You should use Maven because it does all the jobs for you.
Add a pom.xml, let Maven grab everything your plugin needs, code your plugin, ???, Profit!
And, yes, the jar will be pretty much the same.

Well thx :wink: So this topic is solved, now I will try to make a localhost-Sponge-Server to test the plugins ;D