How to get started with Maven Eclipse | Error in pom.xml

Discussion in 'Spigot Plugin Development' started by bys1, Jun 26, 2016.

  1. I'm new to Maven. I've read a lot of tutorials, but I still don't know how to get started.

    How can I create a new Maven project in Eclipse and add Spigot API?
    How do repositories and dependencies work?
    How can I add plugin.yml, and what do I have to set as Main?
    What about exporting to a JAR?

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------

    "Can't find plugin.yml, JAR does not contain plugin.yml"
    Have used @stoneminer02 's pom, and placed the plugin.yml in src/main/resources
     
    #1 bys1, Jun 26, 2016
    Last edited: Jun 28, 2016
  2. In eclipse I think it is File -> Create New... -> Project -> Maven -> Maven Project

    Don't bump within 24 hours of last reply.

    Example pom.xml
    Code (XML):

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>ml.proximyst</groupId> <!-- Main Package can still be ml.proximyst.whatever.evenmore.Main -->
        <artifactId>HellishSurvival</artifactId> <!-- Name of project. Keep it lower case, unlike me :3 -->
        <version>1.0-SNAPSHOT</version>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <packaging>jar</packaging>

        <properties>
            <spigot.version>1.10-R0.1-SNAPSHOT</spigot.version>
            <spigot.groupId>org.spigotmc</spigot.groupId>       <!-- To switch between Bukkit & Spigot -->
            <spigot.artifactId>spigot-api</spigot.artifactId>   <!-- To switch between Bukkit & Spigot -->
        </properties>

        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
        </repositories>
        <dependencies>
            <!--Spigot API-->
            <dependency>
                <groupId>${spigot.groupId}</groupId>
                <artifactId>${spigot.artifactId}</artifactId>
                <version>${spigot.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>${spigot.groupId}</groupId>
                <artifactId>${spigot.artifactId}</artifactId>
                <version>${spigot.version}</version>
                <classifier>javadoc</classifier>
            </dependency>
            <dependency>
                <groupId>${spigot.groupId}</groupId>
                <artifactId>${spigot.artifactId}</artifactId>
                <version>${spigot.version}</version>
                <classifier>sources</classifier>
            </dependency>
        </dependencies>
    </project>
    You'd just export it like normal

    Main in plugin.yml/plugin.yaml is still the same like always. src -> main -> java is the folders you have to go thru.
    Inside there you put packages. The packages you put here is your main package. My main class is then in src->main->java->ml.proximyst.hellishsurvival.Main, so I'll put in the plugin.yml as I did:
    Code (YAML):

    name
    : HellishSurvival
    author
    : Proximyst
    version
    : DEV
    description
    : HellishSurvival's custom plugin.
    main
    : ml.proximyst.hellishsurvival.Main
    (I use the CommandMap to register commands, so ignore the fact that there are none there)

    The plugin.yml goes into src->main->resources, along with config.yml and other classes at root classpath.
     
    • Informative Informative x 1
  3. Thank you, could you please explain scopes and classifiers?
     
  4. Scope: Compile with the plugin? Is it going to be there for you? (always use provided on plugins like factions, and essentials due them being functional. API's are nice to compile)
    Classifier: Every item is classified as a library unless you say "THIS IS A JAVADOC!" or "THIS IS A SOURCES JAR!"
     
  5. So when I use an API like Vault or something I have to use <scope>essentials</scope>

    What is the difference between Library and source?
     
  6. No, not like that.
    The artifactId and groupId defines that you're using essentials.
    Scope is just to say where it is. 'provided' is that it's on the server already.
    'compile' is to put classes in the jar with it
    'runtime' is that it loads on runtime.

    Library is that it's a jar that you're using, like an external jar in build path.
    Source is the actual source of the artifact.
    Javadoc is the javadoc of the artifact.
     
  7. so when the system tired of finding the api file in the plugins folder it will look up to maven shade.
     
  8. Oops, read the sentence wrongly :confused:

    Thank you.
    ?
     
    • Friendly Friendly x 1
  9. No problem <3
     
    • Friendly Friendly x 1
  10. "Can't find plugin.yml, JAR does not contain plugin.yml"
    Have used @stoneminer02 's pom, and placed the plugin.yml in src/main/resources
     
  11. Are you running the maven build script (eclipse has a little green triangle button) or are you doing the old export way?

    Also scope is only needed if you are using the maven shade plugin. All dependencies are treated as provided unless otherwise specified.
     
  12. Show your pom?
     
  13.  
  14. Just refresh and export
     
  15. ?
     
  16. You're not supposed to export it now that you've mavenized it. You need to run the maven build script.

     
  17. How can I set the name and where it is saved?