eclipse and line wrapping

Last month, a co-worker referenced an Eclipse setting that I wish I’ve known about for years.  With streams, I typically indent code like:


list.stream().filter(j -> j.disabled)

.map(j -> j.name)

.forEach(System.out::println);

Then I’d let Eclipse format the code and it would turn into a one (or two) line wall of text. I’ve been “solving” that problem by adding comments before some of the methods so Eclipse couldn’t wrap it. Some of those comments are useful for those new to streams. However many are redundant. You probably don’t need a comment that the last line outputs :).

Then my co-worker taught me that there is an Eclipse setting to control the line breaks. Wish this was on by default!

How to configure

If you don’t already have a custom Eclipse formatter:

  1. Eclipse preferences
  2. Java > Code Style > Formatter
  3. New
  4. Enter a name
  5. Click ok

Control line breaks

  1. Edit the profile
  2. Line wrapping tab
  3. Check “Never join already wrapped lines”

gradle in eclipse – egradle vs buildship

TLDR: use BuildShip rather than EGradle.

While everyone on our team uses command line git (rather than egit), most actual coding in Java happens within Eclipse. We ran Ant in Eclipse for deploying robot code and Ant at the command line for other things. I’m not sure if we will use Eclipse to run Gradle, but writing up for the team just in case!

For more on what the Gradle files mean see the main Gradle SmartDashboard post

EGradle

The first thing I did was try out the EGradle plugin. It worked, but wasn’t as smooth as BuildShip. (See below for using BuildShip).

Install EGradle

  1. Help
  2. Eclipse Marketplace
  3. EGradle
  4. Accept license and install
  5. Restart Eclipse

Modify the project you cloned from github

  1. Clone SmartDashboard if you haven’t already
  2. Edit the build.gradle file to add the eclipse profile.  You just have to add the one line and save the file:
    project(':fakeRobot') {
      apply plugin: 'java'
      apply plugin: 'application'
      apply plugin: 'eclipse'

Import the project you cloned from github

  1. File
  2. Import
  3. EGradle > Import gradle root project with all subprojects
  4. Set Gradle root project to the repository you cloned from github

Build

  1. Right click the build.gradle file
  2. Run as > EGradle

EGradle limitations

  1. You had to edit the build.gradle for Eclipse to recognize it.
  2. EGradle doesn’t provide a way to see the build directory so you have to go to the file system. (and yes I tried changing the filters; it just didn’t work)

Trying that again with BuildShip

BuildShip is the official Eclipse.org plugin for Gradle. Wish I knew that before I started!

Install BuildShip

  1. Help
  2. Eclipse Marketplace
  3. BuildShip Gradle Integration
  4. Accept license and install
  5. Restart Eclipse

Import the project you cloned from github

  1. File
  2. Import
  3. Gradle >Existing Gradle project
  4. Set project root directory to the repository you cloned from github (Note that you don’t need to edit the build.gradle file like you had to with EGradle). It also uses the proper project name.

Build

There are multiple ways to do this. I’m showing just one way that maximizes understanding of what is going on.

  1. The Gradle Tasks view is open automatically for this project. (If not, click the project)
  2. Click SmartDashboard to expand
  3. Click build to expand
  4. Right click build (with a green icon to the left) and choose “Run Gradle Tasks”
  5. This automatically opens the Gradle Executions view which shows you what Gradle did in a nice tree. You can click on the Console view to see the actual command line output.
  6. Configure the filters so you can see the Gradle build folder
  7.  F5 to refresh – now you see the build folder.

 

the successor to sysdeo (and mongrel) for launching tomcat from eclipse

I’ve been using Mongrel to launch Tomcat in one click from Eclipse. In Neon, this stopped working. I learned in a comment on that blog post that there’s now a plugin called “Eclipse Tomcat Plugin 9.1.0” that does the same thing. It is advertised as being a successor to Sysdeo. And it is. But so was Mongrel. However, it works in Neon and does the same thing as Sysdeo/Mongrel so it is logically a successor to both!

The process was easy to get going:

  1. Uninstall Mongrel
  2. Restart Eclipse
  3. Install Eclipse Tomcat Plugin 9.1.0
  4. Restart Eclipse
  5. Preferences
  6. Tomcat  – choose version of Tomcat path and Tomcat home

That’s it!