Tuesday, July 21, 2015

Setting up IntelliJ IDEA to run Spring Applications with Jetty

- I needed Servlet 3.0 features (like config through ServletContainerInitializer interface), but unfortunately Gradle's Jetty plugin (as of v2.4) uses Jetty 6, so it doesn't support Servlet 3.0. So I'm not bothering.

- Instead, I used the third party plugin gretty:  http://akhikhl.github.io/gretty-doc/Getting-started.html

- Had problems using gretty with the IDEA's Default Gradle Wrapper (gradle 1.8):

Error:Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
Possible causes for this unexpected error include:
  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
  • Stop Gradle build processes (requires restart)
    In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
    So instead I switched to using Local Gradle Distribution (2.4).

    Use gradle appStart to start the server.
    Use gradle appStop to stop the server.

    Monday, July 20, 2015

    IntelliJ 14 CE not updating Maven Repository Indices

    Was seeing errors when trying to update Maven repositories in IntelliJ 14 CE

    Preferences / Build, Execution, Deployment > Build Tools > Maven > Repositories

    All of the Remote Repositories where showing 'Error'.


    Hitting Update worked occasionally (like maybe 1/20 times)

    Saw this in the Event Log

    10:14:25 AM Unindexed remote maven repositories found. Disable...
                The following repositories used in your gradle projects were not indexed yet:
                http://download.java.net/maven/2
                http://maven.springframework.org/milestone
                http://maven.springframework.org/release
                If you want to use dependency completion for these repositories artifacts,
                Open Repositories List, select required repositories and press "Update" button (show balloon)

    Also saw Exceptions in idea.log (Help / Show Log in Finder)

    Tried alternative WI-FI and Ethernet connections, including the hotspot on my phone.  No change.

    On ths advice of these Threads:
    https://youtrack.jetbrains.com/issue/IDEA-102693
    https://youtrack.jetbrains.com/issue/IDEA-138029

    I removed the -Xmx512m Setting under Preferences / Build, Execution, Deployment > Build Tools > Maven > Importing > VM options for Importer

    Intially, this seemed to work ... but alas I think it was a coincidence.  It worked fine on the first attempt to update repo1.maven.org, but failed on the others...and ultimately failed when retrying repo1.maven.org.

    Then Tried changing the Maven Importing JRE:

    Build, Execution, Deployment > Build Tools > Maven > Importing > JDK for Importer

    from the Default (Use Internal JRE (1.6) ) to the JDK 1.8 I had installed.

    Again, this seemed to work initially....but failed on second attempt.

    Then I tried killing the RemoteMavenServer (java process found using ps aux | grep maven).  This also made the first download attempt work, but subsequent downloads failed.  I suspect changing the -Xmx and JRE in the above attempts was restarting Java ..... and triggering the same effect as killing the maven process.  The problem seems to be in the interaction between IDEA and the external maven process.

    For now, my solution is to kill any existing RemoteMavenServer process before clicking the 'Update' button.  An easy way to do this it to make some trivial change in VM Options for Importer .... which causes IDEA to restart the external maven process.

    This problem is well characterized here:
    https://youtrack.jetbrains.com/issue/IDEA-138029

    Hope JetBrains fixes this one soon.

    Monday, July 6, 2015

    IntelliJ Gradle not resolving dependencies

    Followed the typical process of setting up a simple Gradle project in IntelliJ  IDEA 14 ....but dependencies were not resolving.  Upon hitting the refresh button, each of the gradle dependencies were underlined red....no useful feedback in logs or console.

    I eventually figured out the problem:  Intellij was configured for Gradle offline mode.

    Preferences >> Build, Execution & Deployment > Build Tools > Gradle >> Offline Work

    Global Gradle Settings was set to 'Offline Work'.  I have no idea why, may have been due to a sketchy WI-FI connection I was using.

    After unchecking the box and refreshing the Gradle project, I'm back on track.

    I found it very useful to download and install Gradle for the command line (using gvm)  so I could test Gradle independent of IntelliJ.  I had no problems using command line gradle to download dependencies....telling me the problem was with IDEA.

    It was also helpful to run Gradle tasks (like compileJavaTest) directly using IntelliJ.  While, 'Refresh' produces no useful console output, running Gradle tasks do.... and in this case the error told me the problem was 'Offline Mode'.