IntelliJ Setup: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
Update guide, adding screenshots from IntelliJ IDEA 2021.2 Community edition
Mcroft (talk | contribs)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==== KoLmafia has migrated to the GitHub with gradle builds. ====
[https://www.jetbrains.com/idea/ IntelliJ IDEA] is an IDE for developing Java applications. This guide assumes that you have a recent enough version of Java JDK, Ant, and IntelliJ IDEA. Completing [[Compiling from Source]] is a requirement for this guide, although experienced developers can skip to whatever step is appropriate.
[https://www.jetbrains.com/idea/ IntelliJ IDEA] is an IDE for developing Java applications. This guide assumes that you have a recent enough version of Java JDK, Ant, and IntelliJ IDEA. Completing [[Compiling from Source]] is a requirement for this guide, although experienced developers can skip to whatever step is appropriate.


The following instructions are based on IntelliJ IDEA 2021.2 Community Edition. Instructions for other versions/editions of IntelliJ may be slightly different.
The following instructions are based on IntelliJ IDEA 2021.2 Community Edition. Instructions for other versions/editions of IntelliJ may be slightly different.  The latest version is recommended.


== Create a Project ==
== Create a Project ==
=== Choice 1: Create a new project ===
=== Create a new project ===
''If you already have a working copy of KoLmafia's source code, you can go to choice 2 instead.''
 
# Start IntelliJ IDEA. In the ''Welcome to IntelliJ IDEA'' dialog, click '''Get from VCS'''.<br>[[File:Intellij-setup-c2021.2-welcome.png|300px]]
# Start IntelliJ IDEA. In the ''Welcome to IntelliJ IDEA'' dialog, click '''Get from VCS'''.<br>[[File:Intellij-setup-c2021.2-welcome.png|300px]]
# In the ''Get from Version Control'' dialog, select the '''Repository URL''' tab.
# In the ''Get from Version Control'' dialog, select the '''Repository URL''' tab.
## In ''Version control'', select '''Subversion'''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs.png|300px]]
## In ''Version control'', select '''GitHub'''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs.png|300px]]
## Add a new repository location. To do so, click the '''+''' button next to ''Repositories''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs-subversion.png|300px]]
## Add a new repository location. To do so, click the '''+''' button next to ''Repositories''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs-subversion.png|300px]]
### In the ''New Repository Location'' popup, enter the URL to KoLmafia's Subversion repository. Currently, this is https://svn.code.sf.net/p/kolmafia/code.<br>[[File:Intellij-setup-c2021.2-new-repository-location.png|200px]]
## In the ''New Repository Location'' popup, enter the URL to KoLmafia's GitHub repository. If you have a GitHub account and a Personal Access Token, use  git@github.com:kolmafia/kolmafia.git  If you do not have a GitHub account, use  https://github.com/kolmafia/kolmafia.git<br>[[File:Intellij-setup-c2021.2-new-repository-location.png|200px]]
### Click '''OK''' to close the popup.
## Click '''OK''' to close the popup.
## Once the repository has been added, '''click the repository URL to highlight it''', then click '''Check Out'''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs-check-out.png|300px]]
## Once the repository has been added, '''click the repository URL to highlight it''', then click '''Check Out'''.<br>[[File:Intellij-setup-c2021.2-get-from-vcs-check-out.png|300px]]
# If the ''Destination Directory'' popup appears, choose a directory to check out the working copy.<br>''Caution'': Don't choose a common directory like <samp>C:\Users\&lt;username&gt;\Documents</samp>. Instead, create a new directory under it (by clicking the folder icon) and give it an appropriate name (e.g. <samp>kolmafia</samp>).<br>[[File:Intellij-setup-c2021.2-choose-working-copy-dir.png|200px]]<br>Click '''OK''' to continue.
# If the ''Destination Directory'' popup appears, choose a directory to check out the working copy.<br>''Caution'': Don't choose a common directory like <samp>C:\Users\&lt;username&gt;\Documents</samp>. Instead, create a new directory under it (by clicking the folder icon) and give it an appropriate name (e.g. <samp>kolmafia</samp>).<br>[[File:Intellij-setup-c2021.2-choose-working-copy-dir.png|200px]]<br>Click '''OK''' to continue.
# If the ''SVN Checkout Options'' popup appears, leave everything as-is and click '''OK'''.
# IntelliJ will generate a new project. If it asks you whether to add <code>kolmafia.iml</code> to Subversion, you may click '''Cancel''' to skip it
# If the ''Subversion Working Copy Format'' popup appears, choose the latest version (which is <samp>1.8 format</samp> as of writing) and click '''OK'''.
# IntelliJ will generate a new project. If it asks you whether to add <code>kolmafia.iml</code> to Subversion, you may click '''Cancel''' to skip it.
 
=== Choice 2: Load an existing working copy into IntelliJ ===
# From the IntelliJ IDEA '''File''' Menu, choose '''New'''>'''New Project from Existing Sources...'''
#Choose the directory with the kolmafia build.xml file and press '''Open'''
#Choose '''Create Project from Existing Sources''' and press '''Next'''
#Enter the name KoLmafia and press '''Next'''
#Verify that the project is visible to IDEA and press Finish


=== Add the Ant Build File ===
=== Add the Gradle Build File ===
# Open the Ant Toolbar Item (typically on the right side, and not very large)
# Open the Gradle Toolbar Item (typically on the right side, and not very large)
# Click the '''+''' button to add a build file
# Click the '''+''' button to add a build file
# Choose build.xml from the file selector and press Open
# Choose build.gradle from the file selector and press Open
# Verify that a list of ANT targets appears in the Ant Toolbar
#Run Configurations should contain <code>kolmafia [runShadow]</code>. If it does not, continue to the next steps.
 
#In the Gradle Toolbar click on the elephant to Execute Gradle Task
== Configure Project ==
#A window titled ''Run Anything'' will popup. Search for <code>runShadow</code> and select it
=== Check Project Settings ===
# In the top menu, select '''File''' > '''Project Structure...''' to launch the ''Project Structure'' dialog.
# In the left menu, select '''Project Settings''' > '''Project'''
## set the '''Name''' to <kbd>kolmafia</kbd>
## set the '''Project SDK''' to a version installed on your system. '''This must be at least 1.8'''.
## set the project language level to '''8'''
## set the project compiler output path to the <kbd>&lt;project dir&gt;\build</kbd> subdirectory<br>[[File:Intellij-setup-c2021.2-project-structure-project.png|300px]]
# In the left menu, select '''Project Settings''' > '''Libraries'''
## Add a project library with the name <kbd>kol-library-jars</kbd>:
### Click the '''+''' button (''New Project Library''), then select '''Java''' to add a new project library<br>[[File:Intellij-setup-c2021.2-project-structure-libraries-new.png|300px]]
### If the ''Select Library Files'' popup appears, navigate to <code>&lt;project dir&gt;\lib\jar</code> directory and select ''all'' JAR files. You can <kbd>shift</kbd>+click the first and last JAR files to select multiple files at once.<br>[[File:Intellij-setup-c2021.2-project-structure-libraries-select-jars.png|300px]]<br>Click '''OK''' to close the popup.
### If the ''Choose Modules'' popup appears, ensure that <samp>kolmafia</samp> is highlighted, then click '''OK'''.<br>[[File:Intellij-setup-c2021.2-project-structure-libraries-choose-modules.png|300px]]
### If you followed the steps above, IntelliJ will create a project library using the name of the first JAR file.<br>To rename it, select the library, then select the '''Name''' field and enter <kbd>kol-library-jars</kbd>.<div><ul><li style="display: inline-block;"> [[File:Intellij-setup-c2021.2-project-structure-libraries-rename-library.png|thumb|none|300px|Before renaming]]</li><li style="display: inline-block;"> [[File:Intellij-setup-c2021.2-project-structure-libraries-renamed.png|thumb|none|300px|After renaming]]</li></ul></div>
## Repeat the steps above to add a project library with the name <kbd>kol-source-jars</kbd>, selecting all JAR files under <code>&lt;project dir&gt;\src\jar\</code>.
## Repeat the steps above to add a project library with the name <kbd>kol-test-jars</kbd>, selecting all JAR files under <code>&lt;project dir&gt;\lib\testjar\</code>.
## Click '''Apply'''.
# In the left menu, select '''Project Settings''' > '''Modules'''
## Select the '''Dependencies''' tab
### If you followed the instructions so far, this section will have libraries with incorrect names (i.e. using the names of the first JAR file in each library). Select them all and click '''-''' to remove them.<br>[[File:Intellij-setup-c2021.2-project-structure-modules-remove-bad-libraries.png|300px]]
### Add the correct project libraries by clicking '''+''', then '''Library'''.<br>[[File:Intellij-setup-c2021.2-project-structure-modules-add-library.png|300px]]
#### In the ''Choose Libraries'' dialog, select all project libraries we added so far, then click '''Add Selected'''.<br>[[File:Intellij-setup-c2021.2-project-structure-modules-choose-libraries.png|300px]]
## Select the '''Sources''' tab
### Right-click the '''lib''' and '''src''' folders. If the  and verify that each is marked as ''Sources''
### Right-click the '''test''' folder. If the folder is not marked as '''Tests''', click the menu item to check it.<br>[[File:Intellij-setup-c2021.2-project-structure-modules-sources.png|300px]]
## Select the '''Paths''' tab
### Select '''Inherit project compile output path'''<br>[[File:Intellij-setup-c2021.2-project-structure-modules-paths.png|300px]]
# Click '''OK''' to close the ''Project Structure'' dialog
 
=== Add Run/Debug Configuration ===
# In the top menu, select '''Run''' > '''Edit Configurations...''' to launch the ''Run/Debug Configurations'' dialog.
# Click the '''+''' button, then choose '''Application''' to add a new configuration
# In the '''Name''' Field, enter "KoLmafia"
# Click the icon that looks like a document ("Browse...") to the right of the '''Main Class''' field.
## If the ''Choose Main Class'' popup appears, wait until IntelliJ populates the list of possible main classes, then choose '''<samp>KoLmafia</samp>''' and click '''OK'''
# Add any VM or program arguments needed (typically none)
# Enter the working directory. This is where KoLmafia will store your user data when launched from inside IntelliJ (e.g. <samp>C:\Users\&lt;user&gt;\Documents\kolmafia-workdir</samp>).<br>''Caution'': This should be different from the project directory!
# Add the "before launch" tasks:
## Click '''Modify options''' at the top right and select '''Add before launch task'''
## Add the '''set.released.false''' Ant task:
### Click the '''+''' button to the right of ''Before launch'', then '''Run Ant target'''.
### If the ''Choose Ant Target to Execute'' popup appears, select '''set.released.false''' and click '''OK'''.
## Repeat the steps above to add the '''set.version''' Ant task
## Repeat the steps above to add the '''unset.properties''' Ant task
## Drag-and-drop the tasks to ensure that each task is executed in the following order:
### Run Ant target 'set.released.false'
### Run Ant target 'set.version'
### Build
### Run Ant target 'unset.properties'
# Click '''OK''' to close the ''Run/Debug Configurations'' dialog.
 
Test by pressing the Run arrow next to your config name in the toolbar at the top of the window.


== Optional Steps ==
===How to build and run/debug===
* Setup SVN to update from IntelliJ (can still be done from the command line or a tool)
#Click the drop down in the top right and select the desired option
*# TODO: FIXME...
##<code>kolmafia [runShadow]</code> is the application itself
* To use the Reformat Code feature, download the [[:File:KoLMafia Style.xml|KoLMafia Style Definitions]] and import them in the IntelliJ Code Style Preferences.
##<code>Tests in 'KoLMafia'</code> are the unit tests
#Click the play button to build and run
#Or click the bug button to build and debug

Latest revision as of 01:09, 5 December 2023

KoLmafia has migrated to the GitHub with gradle builds.

IntelliJ IDEA is an IDE for developing Java applications. This guide assumes that you have a recent enough version of Java JDK, Ant, and IntelliJ IDEA. Completing Compiling from Source is a requirement for this guide, although experienced developers can skip to whatever step is appropriate.

The following instructions are based on IntelliJ IDEA 2021.2 Community Edition. Instructions for other versions/editions of IntelliJ may be slightly different. The latest version is recommended.

Create a Project

Create a new project

  1. Start IntelliJ IDEA. In the Welcome to IntelliJ IDEA dialog, click Get from VCS.
  2. In the Get from Version Control dialog, select the Repository URL tab.
    1. In Version control, select GitHub.
    2. Add a new repository location. To do so, click the + button next to Repositories.
    3. In the New Repository Location popup, enter the URL to KoLmafia's GitHub repository. If you have a GitHub account and a Personal Access Token, use git@github.com:kolmafia/kolmafia.git If you do not have a GitHub account, use https://github.com/kolmafia/kolmafia.git
    4. Click OK to close the popup.
    5. Once the repository has been added, click the repository URL to highlight it, then click Check Out.
  3. If the Destination Directory popup appears, choose a directory to check out the working copy.
    Caution: Don't choose a common directory like C:\Users\<username>\Documents. Instead, create a new directory under it (by clicking the folder icon) and give it an appropriate name (e.g. kolmafia).

    Click OK to continue.
  4. IntelliJ will generate a new project. If it asks you whether to add kolmafia.iml to Subversion, you may click Cancel to skip it

Add the Gradle Build File

  1. Open the Gradle Toolbar Item (typically on the right side, and not very large)
  2. Click the + button to add a build file
  3. Choose build.gradle from the file selector and press Open
  4. Run Configurations should contain kolmafia [runShadow]. If it does not, continue to the next steps.
  5. In the Gradle Toolbar click on the elephant to Execute Gradle Task
  6. A window titled Run Anything will popup. Search for runShadow and select it

How to build and run/debug

  1. Click the drop down in the top right and select the desired option
    1. kolmafia [runShadow] is the application itself
    2. Tests in 'KoLMafia' are the unit tests
  2. Click the play button to build and run
  3. Or click the bug button to build and debug