IntelliJ IDEA 설정하기

This article describes how to configure your IntelliJ IDEA workspace for plugin development with SpongeAPI and a build system such as Maven or Gradle or the Minecraft Development plugin.

If you want to create your project completely from scratch, please skip ahead to the Gradle or Maven sections. Using the Minecraft Dev plugin sets up a working starting point and eliminates some of the guesswork in getting your project off the ground.

Using IDEA Minecraft Dev Plugin to Create a Working Starting Point

The Minecraft Development plugin for IntelliJ is a great plugin by a community member which makes plugin project creation much easier while also providing some neat and useful features for development. By default, it will create a project which uses Gradle as the build tool.

Minecraft Dev Plugin 설치하기

이 플러그인은 JetBrains Intellij 의 플러그인 Repository 에 존재합니다.

Because of this, you can install the plugin through IntelliJ’s internal plugin browser. Navigate to File -> Settings -> Plugins and click the Browse Repositories... button at the bottom of the window. In the search box, simply search for Minecraft. You can install it from there and restart IntelliJ to activate the plugin.

Creating Your Project from a Template

  • IntelliJ IDEA 프로그램을 실행합니다.

  • Create New Project를 클릭하세요.

  • 팝업 창에서 Minecraft 를 선택하세요.

  • Project SDK 의 버전을 Java 8/1.8 로 설정해야 합니다.

  • 프로젝트 타입을 Sponge plugin 으로 선택한 후, Next 를 클릭해주세요.

  • Group ID, Artifact ID, Version 을 입력합니다.

    • Your Group ID should usually correspond to your Java package name. See 메인 플러그인 클래스 for details.

    • Your Artifact ID should usually correspond to your plugin ID you chose earlier, e.g. myplugin.

    • Your Version is up to you. See Version Numbers for details.

  • Gradle 과 Maven 중 원하는 빌드 도구를 선택한 후, Next 를 클릭해주세요.

  • Plugin NameMain Class Name 을 원하는 대로 설정되어 있는지 확인해주세요.

  • description, authors, website, 그리고 dependencies 를 원하는 대로 지정해주세요.

  • Click Next to move on.

  • Verify your project name, location, and module information, then click Finish.

  • The plugin will create a main java file as a starting point, with the logger already injected. You may add a logger.info() statement in the onServerStart event handler to verify that the plugin is working when you run it.

Editing the Project Configuration

Refer to the Gradle or Maven configuration sections, depending on what you chose during project creation.

Creating a Plugin from Scratch – Gradle

  • IntelliJ IDEA 프로그램을 실행합니다.

  • Create New Project를 클릭하세요.

  • Select Gradle in the popup.

  • If you want, select any additional libraries and frameworks you desire, for example Kotlin.

  • Project SDK 의 버전을 Java 8/1.8 로 설정해야 합니다.

  • Click Next to move on.

  • Group ID, Artifact ID, Version 을 입력합니다.

    • Your Group ID should usually correspond to your Java package name. See 메인 플러그인 클래스 for details.

    • Your Artifact ID should usually correspond to your plugin ID you chose earlier, e.g. myplugin.

    • Your Version is up to you. See Version Numbers for details.

  • Next를 두 번 클릭하고, 프로젝트 이름을 지정한 뒤 Finish를 누르세요.

  • The project will be created without a src directory. If you add java files to the incorrect location underneath the project, they will be ignored and not compiled, so it is a good idea to enable the checkbox “Create directories for empty content roots”, found in:

    • Windows: File -> Settings -> Build, Execution, Deployment -> Gradle

    • Mac: Intellij IDEA -> Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle

  • Enabling Use Auto-import in the same location will allow change to the gradle configuration to automatically reload without IDEA prompting you each time.

  • Upon enabling those settings, a /src/main/java directory should be created, where you can start creating your main plugin code files.

Editing the Build Script

  • 네비게이션 메뉴에서 build.gradle를 열고 dependency를 추가합니다.

  • Edit the build script according to the instructions at Gradle 설치하기.

  • IntelliJ 윈도우의 우측에서 Gradle tab 을 열고 새로고침 버튼을 누릅니다.

  • Gradle 설정이 끝났습니다! 이제 당신의 플러그인을 만들어 보세요.

Creating a Plugin from Scratch – Maven

Creating Your Project

  • IntelliJ IDEA 프로그램을 실행합니다.

  • Create New Project를 클릭하세요.

  • Select Maven in the popup.

  • Project SDK 의 버전을 Java 8/1.8 로 설정해야 합니다.

  • Click Next to move on.

  • Group ID, Artifact ID, Version 을 입력합니다.

    • Your Group ID should usually correspond to your Java package name. See 메인 플러그인 클래스 for details.

    • Your Artifact ID should usually correspond to your plugin ID you chose earlier, e.g. myplugin.

    • Your Version is up to you. See Version Numbers for details.

  • ``Next``를 클릭합니다.

  • 프로젝트 이름을 입력하고 Finsh를 클릭합니다.

Editing the Project Configuration

  • 탐색기에서 ``pom.xml``를 여세요.

  • Edit the build configuration according to the instructions at Maven 설치하기.

  • Refresh your Maven project.

  • 창이 뜬다면, Maven 변경 사항을 불러오세요.

Testing Your Plugin

The following instructions are a quick way to test your plugin, but won’t be the most efficient way to iteratively develop.

To make a .jar file, using Gradle:

  • Go to View -> Tool Windows -> Gradle

  • Under Tasks -> Build, click on jar

  • The build process should create the jar underneath build\libs

To make a .jar file, using Maven:

  • Go to View -> Tool Windows -> Maven Projects

  • In the Maven Projects window, expand your project’s name

  • Under Plugins, expand jar

  • Double click jar:jar

  • The build process should create the jar underneath target

Copy your jar file to the mods directory of a working Sponge server, then restart the server to test.

For a more efficient development process, see 플러그인 디버그 for instructions on running both the Sponge server and your plugin from within IDEA. This process allows for hot-swapping, allowing you to change plugin code without restarting the server.

Importing An Existing Project (Gradle or Maven)

If you’ve already started with your project and want to import it again at a later point you need to import it instead of re-creating it inside your IDE:

  • Click File > Open or Import Project.

  • Gradle: Navigate to the project’s build.gradle file and select it.

  • Maven: Navigate to the project’s pom.xml file and select it.

  • Make sure the settings are as you desire and click Ok.

Git에 병합하기

JetBrains offers in-depth documentation on using their Git integration:

https://www.jetbrains.com/help/idea/using-git-integration.html