GitHub / Maven howto

Discussion in 'Resources' started by petteyg359, Apr 5, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    petteyg359

    Copying my post from an apparently non-public forum so that everyone can read it :)

    How to use git:
    Create an account on GitHub. Create a repository using the name of your project. On Windows, install MSYSGIT. On Linux, use your package manager to install git. Open up a [msysgit-]bash prompt, cd to your project folder, and:
    Code:
    git init
    git remote add origin git@github.com:USERNAME/PROJECTNAME.git
    git add SRC
    git commit -m "Commit message goes here!"
    git push -u origin
    
    Where SRC is your source files. If they're all in a directory named "src" (If they aren't you should learn Maven (also CLI-based). It makes building jars so much quicker :)).
    For future updates:
    Code:
    git add SRC
    git commit -m "Updated updates with an updating updater of updatedness!"
    git push
    
    You only have to use "-u origin" on the very first push. After that, it knows where you're pushing to.

    How to use Maven:
    Eclipse and IDEA should be able to automatically load Maven projects if they're in the right format. Use the following layout:
    PROJECTNAME/
    src/
    main/
    java/
    com/
    yourname/
    PROJECTNAME/
    PROJECTNAME.java​
    resources/
    plugin.yml​
    pom.xml​
    You can use some other layout for the package (com/yourname) if you actually own a domain name, but DO NOT USE com, net, or org/bukkit (or com, net, or org.bukkit in your java file).
    In pom.xml, put the following:
    Code:
    <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>com.yourname</groupId>
      <artifactId>PROJECTNAME</artifactId>
      <version>0.1</version>
      <name>PROJECTNAME</name>
      <url>http://yourdomainifyouhaveone.com/yourprojectpageifyouhaveone</url>
      <dependencies>
        <!-- You don't necessarily need to depend on Permissions if you don't want to, but this is how you add a dependency -->
        <dependency>
          <groupId>com.nijikokun.bukkit</groupId>
          <artifactId>Permissions</artifactId>
          <version>2.5.5</version>
          <type>jar</type>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.bukkit</groupId>
          <artifactId>bukkit</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <type>jar</type>
          <scope>compile</scope>
        </dependency>
      </dependencies>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    </project>
    
    You need to download maven from maven.apache.org. You might need to add whatever folder you put it in to your PATH. In Windows, see this page. Just add ";whereveryouextractedthezipto/bin" to the end. If there's already a semi-colon on the end, then you don't need to add another. In Linux, just install maven (or maven-bin) from your package manager.
    To install Bukkit so that Maven can find them, download the jars, then use the following command:
    Code:
    mvn install:install-file -Dfile=whereveryoudownloadedbukkit-0.0.1-SNAPSHOT.jar -DgroupId=com.bukkit -DartifactId=bukkit -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
    The same command can be modified slightly to install any other jar you depend on. For Permissions:
    Code:
    mvn install:install-file -Dfile=whereveryoudownloadedPermissions-2.5.5.jar -DgroupId=com.nijikokun -DartifactId=Permissions -Dversion=2.5.5 -Dpackaging=jar
    Replace file, groupId, artifactId, and version as needed, just make sure you use the right strings.

    Of course, if they've released the source (and have a decent pom.xml, which some do not (/me wags finger at GroupManager)), you can just download it and use 'mvn install' to compile it yourself.

    Then, you can just cd into your project directory and type "mvn install" and it will build your jar with all dependencies, and you can copy it from the repository to your plugins folder.
     
    GarethNZ, compwhizii and rakiru like this.
  2. Offline

    Daniel Heppner

    Is there a way so that Maven automagically downloads the dependencies? I've seen it done with CommandBook. It made it so easy to compile, just type a command. Also, I saw something in CommandBook's pom.xml about GitHub, and I'm wondering if that lets you have it automatically upload to GitHub. That would be so awesome, thanks for the tutorial. :)
     
  3. Offline

    petteyg359

    You can add repositories for it to search for dependencies:
    Code:
    <repositories>
     <repository>
      <id>sk89q-mvn2</id>
      <url>http://mvn2.sk89q.com/repo</url>
     </repository>
    </repositories>
    Just add as many repository sections inside <repositories /> as needed, with each having a unique id.
     
  4. Offline

    Shamebot

    There's the bukkit repo, repo.bukkit.org, but since they all have the same version it doesn't seem to work.
    Can I somehow force maven to always download the newest?
    Or download the one with a specific build.number in the metadata?
     
  5. Offline

    petteyg359

    The Bukkit repository URL I've seen used is http://artifacts.lukegb.com/artifactory/repo
    I'm not sure how maven deals with the version string remaining the same. I just keep a fork of Bukkit.git and build my own bukkit.jar from that.
     
  6. Offline

    Torrent

    Ah, seems so easy lol.

    Cheers for this - will update my GitHub later today :p
     
  7. Offline

    halvors

    What repo do i need to add for Permissions 3.x?
     
  8. Offline

    _ralts

    You just use sk89q's dummypermissions to compile. The WorldEdit pom.xml file has an excellent example of this. It really doesn't matter what version of Permissions you use to compile it, as long as it has the same API.
     
  9. Offline

    halvors

    So there is no offcial. Using bukkit's now anyway.
     
  10. Offline

    Jaker232

    So do I just install the source code inside the folder my repository is located in, then execute the commands in the [.code] tag? I'm confused a little bit.
     
Thread Status:
Not open for further replies.

Share This Page