Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: A small typo in the class name

...

  • Choose "Create project from existing sources"
    Image Modified
  • Set the project files location to the "src" subdirectory and choose a project name
    Image Modified
  • unmark all sources but "src/main"
    Image Modified
  • no library should be found, click next
    Image Modified
  • click next on module review
    Image Modified
  • web facets should be detected, but they are not necessary. Uncheck them
    Image Modified
  • click on "finish"

...

  • Open the project structure window
  • Choose a 1.6 version of the JDK
    Image Modified
  • Under the modules section, make the "test" folder a "test sources" folder
    Image Modified

    Perform an Ant build

...

Then register the build.xml file in IntelliJ IDEA (Ant build tab on the right of the screen, "plus" button). You'll be able to launch the Ant build from IntelliJ IDEA now (use the "run" button from the Ant build tab). You could choose to run the Ant build externally, that is not a problem.

Image Modified

IntelliJ IDEA will run the ant build which will download the required third party libraries for you. Build duration depends on whether you already have the dependencies in a local maven repository.

Image Modified

Now your base directory includes a "target" directory where you will find various build artifacts :

Image Modified

Update the project structure

We will make use of those artifacts to create a working Groovy build from IntelliJ IDEA. To illustrate this, we will try to compile and debug (add a breakpoint) to the groovy.json.JsonBuilderTest which can be found under the test directory. Open this file in IDEA (tip, use CTRL+N, then type JBT, IntelliJ will find the class for you) :

Image Modified

You will notice the message at the top of the editor window which states that the Groovy SDK is not found. This is for the reasons we explained sooner : IntelliJ IDEA wants to build your Groovy files with the Groovy SDK you choose. As the project you are building is Groovy itself, it is a nonsense, so we must workaround this.

...

  • Open the project structure
  • Under the "modules" section, choose the "dependencies" tab then click on the "add" button
  • choose "2. library" : we are going to create a library for building groovy
    • name it "Groovy local build"
    • attach classes, and choose the target/dist/groovy-all.jar file
    • attach jar directories, and choose the target/lib/compile, target/lib/runtime and target/lib/test directories

Image Modified

With this library attached to the project, you will be able to start building Groovy from sources. However, there are still little modifications to be done.

...

Now if you right click on the class name of the JsonBuilderTest, you will notice that IntelliJ IDEA suggests to create a run configuration for the test. Do it. If you try to run it, IDEA will start building Groovy from sources, but you will fail with those errors :

Image Modified

The first errors are there because 3 files (BSFTest, CacheBSFTest and MBeanTest) are outside the scope of the project we created (they are not inside the Groovy src directory). To have IDEA build the project, you can exclude those files from the build by right clicking on each file where there is a problem in the build console and choose "Exclude from compile". The last error is an IDEA stub compilation error that you can safely ignore too. If you were to run the test configuration again, it would fail on UberTestCaseJavaSourceCodehausPackages and UberTestCaseJavaSourceGroovyPackagesNonSecurity because of the files we just have excluded, so exclude them from compilation too.

Now run the test configuration again: now it works ! Congratulations, you have successfully setup IDEA to build Groovy from sources !

Image Modified

You can add a breakpoint in JsonBuilderTest, and run the test configuration in debug mode. You will notice that IDEA performs a breakpoint as needed :

Image Modified

Updating the compiler itself

Now imagine the class you are working is related to the compiler. As the class you are updating is directly related to the compilation process, will IDEA use the class from the jar in target/dist/groovy-all.jar or the class you have just updated ? For reasons we ignore, it seems that IDEA just does it fine : if you update a compiler class, the compilation process itself will use this class instead of the one in the jar file. To check this, update the AsmClassGenetator AsmClassGenerator class and add this line at the beginning of the public void visitClass(ClassNode classNode) method :

...

Now run your test again (you must update the test file so that intellij idea builds it again). You will notice that the build process will fail as expected, so everything is fine !

Image Modified