creating a new VS code gradle project

I need to create a really simple Gradle project from scratch for my Oracle Code One hands on lab. I also need need to gain more experience with Visual Studio Code since we are using it soon for FIRST robotics. Seems like a good opportunity to combine my tasks here!

First, I re-read my first impressions of VS Code blog post. That reminded me of the keyboard shortcut to get context sensitive options. Ok. now I’m ready to get started.

(I intentionally didn’t use an archetype to get more experience using the editor)

Installing Gradle extension

I installed the Gradle Language Support plugin. Not sure if I needed it, but the syntax highlighting is nice. I don’t see a wizard option to create a Gradle project. This means I have to create an empty project

Creating a new project

I created an empty folder on my filesystem. Then I added that folder to VS Code. This created an empty project with the name I wanted.

Create the build file

I tried click “New File” on the editor. That created an untitled file that I couldn’t figure out how to rename. I could figure out how to delete it so I did that.

Then I used the keyboard shortcut to open help and choose “File: New”. Great that prompts me for a name. (I then realized that I could have just right clicked to have the new file option.)

I then typed a small gradle build file

apply plugin: 'java'</div>
repositories {
<div>  mavenCentral()</div>
<div>dependencies {</div>
<div>  compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8'</div>
Create directory structure
I then created the src/main/java and src/test/java folders. I was able to right click to create the folders so this was easy enough.
Create Java packages
I couldn’t find an easy way to create packages/classes, so I created a bunch of folders and a file with the extension .java. This did work and the IDE let me type in my class.
However, when i did the same for my unit test, I was not able to open the empty file. At this point, I gave up and went back to Eclipse. I need to poke at this when I have more time.
Also, it appears the FIRST robotics plugin overrides the behavior of the default gradle run.
Editing a project
I created my first project in Eclipse. The second was a copy of the first with some renames and minor behavior changes. I copied the first project on disk. Then I opened that folder and made all the edits in VS Code. That was easy; even autocomplete worked as expected. My only problem with the second project was running the gradle build and I think that’s the FIRST robotics plugin.
Other observations
  • Since I created my folder/project inside a git repo on my machine, VS Code was smart enough to detect this. It was also helpful for seeing what I forgot to add to the .gitignore fil.
  • I feel like I got dropped into someone else’s home. I was able to do everything I needed. But not in an efficient way.



Leave a Reply

Your email address will not be published.