Skip to content

How to work with GS Collections

goldmansachs edited this page Jul 22, 2014 · 1 revision

Building GS Collections in IntelliJ with Maven

Software you will need

GS Collections Source Code

The source code is available here in GitHub. You can clone it using Git or download the zip file.

git clone https://github.com/goldmansachs/gs-collections

IntelliJ

You can use either the free version (IntelliJ Community) or the paid version (IntelliJ Ultimate). It's probably possible to use Eclipse as well. However there is an inconsistency between javac and ecj (Eclipse Compiler for Java) that prevents ecj from compiling GS Collections. If you use Eclipse, make sure to configure it to use javac.

You'll need the IntelliJ plugins for Maven Integration, Scala, and JUnit. Click File -> Settings... -> Plugins. Install any of the missing plugins and restart the IDE.

Open the project in IntelliJ using File -> Open ...

The IntelliJ project files are checked into the root of the project at ./.idea

If IntelliJ prompts you to remove modules or reload the project for language level changes, click no for now.

Java

The library modules in GS Collections are compatible with Java 5 (gs-collections-api, gs-collections, and gs-collections-testutils). The test modules use features from Java 8 (unit-tests, performance-tests, jmh-tests, etc.) Install the Java 8 SDK if you don't already have it.

In IntelliJ, click File -> Project Structure... SDKs, the + icon, JDK, and then choose the location of the Java 8 SDK on your system. For the name, enter 1.8. While still in the Project Structure menu, switch to Project and under Project SDK choose 1.8 which you just set up.

If IntelliJ prompts you to reload the project again, now you can go ahead.

Maven

The GS Collections build performs code-generation to create primitive collections (like IntArrayList and LongArrayList) from templates (like primitiveArrayList.stg). You'll need to run the full build once, or the IDE will complain that it can't find these Java files.

Download and/or install Apache Maven if you don't already have it. Any version since 3.0 should work. Optionally set the M2_HOME environment variable to the location where you unzipped or installed Maven. Otherwise, in IntelliJ you can click File -> Settings... -> Maven and configure the Maven home directory to location where you unzipped Maven without setting environment variables.

Open the Maven Projects tool window. If it's hidden, check the tool window icon in the lower left (it's a rectangle with no caption). In the Maven Projects window, click the gear in the upper right and select group modules. That should decullter the view and leave the Parent project up top. Expand the module named Goldman Sachs Collections Parent Project (root), then Lifecycle. You'll see the standard build targets. Use Ctrl+click to select clean and install. Then click the play button in the Maven Projects tool window (there's another unrelated play button for running JUnit tests). Once it's done, you should rarely need to run the maven build. Running the Maven build is only necessary when you need to force a clean build or recreate the generated sources because you edited stg template files. Usually it's enough to just run unit tests, which triggers an incremental compile.