Resource [GUIDE] Windows - Extremely productive development environment

Discussion in 'Spigot Plugin Development' started by PiggyPiglet, Sep 7, 2019.

  1. Before I get started, please note this guide is specifically made for IntelliJ. The same concepts may be achievable in other IDE's, but I don't know how. Also, sorry in advance for how many images, but I feel they're necessary, as when I've tried to explain this process in the past, people simply couldn't find the options I was referring to.

    First, there are a couple of things you'll need to install. In IntelliJ, download the Run Configuration as Action plugin. This allows us to bind maven/gradle tasks to a button, which can then be binded to a keybind.

    You'll also need DCEVM. Assuming you're using Oracle JVM or HotSpot, the default hotswapping capabilities of both are extremely limited, restricting you to only being able to hotswap method bodies. DCEVM greatly improves upon this, by allowing you to hotswap nearly anything. DCEVM can either be added onto an existing JDK (<8), or fully replace the JDK (<11). I'm going over the latter in this guide, but the former isn't necessarily difficult to achieve either.

    Download the latest binary zip from here, then extract it into C:\Program Files\Java\. Your directory tree should look something like this after:
    upload_2019-9-8_0-23-52.png

    We can now move onto actually setting up the IDE. The first step, is creating your build task. If using maven, click on ADD CONFIGURATION in the top right corner of your screen.
    upload_2019-9-8_0-39-12.png
    In the window that opens, click the + in the top left, and select Maven
    upload_2019-9-8_0-40-1.png
    I'd recommend just calling it Package, but it's entirely up to you. Set the Command line to package
    upload_2019-9-8_0-41-49.png
    You can then click Apply and then OK at the bottom right.

    If using gradle, executing a task will automatically create a configuration for you. For example, running shadowJar will automatically create a shadowJar configuration.
    [​IMG]
    Upon completion and validation that the configuration is working, press control + alt + s to open up settings. Then navigate to the Appearance & Behaviour section, and click Menus and Toolbars.
    [​IMG]
    Find and open the Navigation Bar Toolbar dropdown, and figure out where you want to position the item. I usually put mine after Run anything. Simply highlight the element that's above the position you wish to place your icon in, then click the + at the top of the window, and select Add Action
    [​IMG]
    Open Plug-ins > Run Configuration as Action, and find your task.
    [​IMG]
    If you deem it necessary, you can set an icon like I've done myself, however it's purely cosmetic. Click on the task, then click OK. Verify that the icon is on your toolbar, by clicking Apply and OK in the bottom right corner of your Settings window, then looking for the icon. If it's there, open settings back up with ctrl + alt + s, then open the keymap section.
    [​IMG]
    Navigate to Plug-ins > Run Configuration as Action > your task, right click on it, and add keyboard shortcut. I personally use ctrl + b, but it's up to you. Once set, in the search box in the top right, search Reload Changed Classes. Add a binding for Main menu > Run > Reload Changed Classes. I personally use alt + r.
    [​IMG]
    Lovingly caress the Apply and OK buttons, and verify your build keybind is working. We'll test alt + r later. For absolute maximum efficiency, I'd recommend configuring your build tool to automatically output the jar into your test server's plugin folder. Speaking of test servers, let's set one up.

    Actually... not so fast, before we can do that, we need to set our JDK. Open project structure (control + shift + alt + s), and click project. Then, click new in the Project SDK section. Navigate to the path your dcevm installation is at, and add it. Then select said installation. Also change the project language level to 11.
    [​IMG]
    Once again, hit apply and ok.

    Ok, now we can create the test server. Create a new folder in your projects root directory, and call it whatever you want, then put your spigot jar in. Click on the top right, where your configurations are, and add a new configuration. Set it to Jar Application.
    [​IMG]
    Fill it out with the path to your jar, and the directory your jar is in. If you wish, you can add -DIReallyKnowWhatIAmDoingISwear as a VM option, which will stop the outdated spigot warning from showing. Set the JRE to the one we added before.
    [​IMG]
    Apply & OK. Verify the server is working by starting it, and accepting the eula ofc. Let it run through it's world gen stage, then stop is via the proper command. Believe it or not, that was the last stage, everything is ready now.

    Set your current configuration to the spigot server. You'll be able to run this with shift + f9, and build the plugin with whatever bind you set earlier. If the server is running and you've changed the code, use your reload keybind to hotswap.
    [​IMG]
     

    Attached Files:

    #1 PiggyPiglet, Sep 7, 2019
    Last edited: Sep 29, 2019
    • Like Like x 4
    • Useful Useful x 3
  2. Benz56

    Moderator Supporter

    Very nice, detailed, and extensive tutorial - kudos!

    For all of you who do not want to set all of this up, I personally recommend BileTools. It'll automatically detect when you build your plugin in you IDE and swap it for you instantly while the server is running.
     
    • Agree Agree x 2
    • Informative Informative x 2
  3. BileTools looks cool, but I don’t think it’s a replacement for DCEVM. For example, imagine you’re in a delicate situation, where you’ve got objects stored in memory that aren’t easily reproducible. With dcevm, no problem, just add the code to interact with it. Such objects would be lost with biletools though.
     
    • Informative Informative x 1
  4. Benz56

    Moderator Supporter

    You're completely right! I forgot to mention that BileTools reloads the entire plugin and not just a segment of it. Haven't encountered such a situation yet though, but sure, it might be useful for some to have persistence between builds.
     
  5. Trying this on the latest Intellij with Spigot, Reload Changed Classes does nothing.

    Looks cool if I could get it to work though!

    EDIT: I think I just need to run it in Debug mode.
     
    #5 Big_Bad_E, Sep 14, 2019
    Last edited: Sep 15, 2019
  6. Hello, I am trying to set this up and have followed your guide to the end. Unfortunately I get the error of "Hot swap failed" as seen here http://prntscr.com/p68fsz this is when running what you have set to "alt+r". Any help is appreciated :) The server is running and the package is built successfully.
     
  7. Are you using any sort of relocation? That error is usually caused when your build tool (maven or gradle) is doing relocations, or if you're relocating classes at runtime. Hotswapping doesn't use your build tool, resulting in an internal inconsistency regarding class names/packages.
     
    #7 PiggyPiglet, Sep 15, 2019
    Last edited: Sep 15, 2019