Skip to content

Creating a project

alexstaeding edited this page Feb 7, 2020 · 7 revisions

This guide will follow the development of a project called SimplePvp and can be read as a follow-along while you are creating your plugin. The goal is to create a plugin that will track kills and deaths for each player.

First Steps

Note: Unless specified, all commands are to be run in your project's root directory.
You can check your current directory with "pwd" on unix based machines or "cd" on windows.

To start working with Anvil, create a new Gradle project in your IDE of choice (we recommend IntelliJ IDEA).

  1. File > New > Project
  2. Select Gradle
  3. Use Java 1.8 as project SDK
  4. Make sure Kotlin DSL buildscript is disabled
  5. Make sure only java is selected under Additional Libraries and Frameworks
  6. Click next
  7. Pick an ArtifactId and GroupId for your project (name is usually the same as ArtifactId
  8. Click finish

Updating Gradle

Note: If you are on windows, use "gradlew" instead of "./gradlew" for the rest of the guide.

You should now be looking at an empty project. The first thing we will do is update Gradle to the latest version by running the following commands in the terminal.

Note: Gradle 6.1.1 is the latest version at the time of this writing. If there is a later one available, use that instead.
  1. ./gradlew wrapper --gradle-version 6.1.1
  2. ./gradlew wrapper

Initializing git and the submodule

While not strictly necessary, it is recommended that you create a git repository for your project. If you do not have git installed, please install git. If you choose to not use git or do not wish to use Anvil via git submodule, please skip to the next section.

To start with git, run

git init

This initializes an empty git repository in your current directory. The next step is to add Anvil as a git submodule. To do this, run

git submodule add https://github.com/MilSpecSG/Anvil

This adds Anvil as a submodule to your current project so that you can use it later. The final step to adding Anvil is adding the Gradle module definitions in settings.gradle. It should look like this:

rootProject.name = 'SimplePvp'

include 'Anvil'

include 'Anvil:anvil-api'
include 'Anvil:anvil-api:anvil-api-mariadb'
include 'Anvil:anvil-api:anvil-api-mongodb'
include 'Anvil:anvil-api:anvil-api-xodus'

include 'Anvil:anvil-common'
include 'Anvil:anvil-common:anvil-common-mariadb'
include 'Anvil:anvil-common:anvil-common-mongodb'
include 'Anvil:anvil-common:anvil-common-xodus'

include 'Anvil:anvil-core'
include 'Anvil:anvil-core:anvil-core-api'
include 'Anvil:anvil-core:anvil-core-common'
include 'Anvil:anvil-core:anvil-core-sponge'
include 'Anvil:anvil-core:anvil-core-velocity'

include 'Anvil:anvil-sponge'

include 'Anvil:anvil-velocity'

The next step is to add a .gitignore file. This tells git which files to ignore when making commits. You can just copy and paste it from here and put it in your root project directory.

Note: If you see the message "You can configure Gradle wrapper to use distribution with sources. It will provide..." above the `build.gradle` file in Intellij,
go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and
set "Use Gradle from" to "'wrapper' task in Gradle build script". Click Apply and Ok to save your changes.

Please head on over to Multiplatform design to continue.