Create a Java (Gradle) project with VS Code and develop it on a Docker container


Looking back on 2020, the shock of encountering the Remote Development Extension Pack of VS Code cannot be described in words.

For me, with Remote Container these 8 languages, I will conquer all of them because there is a development container sample with a development environment made by MS. Although I was enthusiastic, I was not able to do anything due to my daily busyness, so I first worked on Java (Maven), but here I will try working on Java (gradle) To

-Create a Java (Maven) project with VS Code and develop it on a Docker container

Create a repository on GitHub

Create a new repository on GitHub. I've named it CCI-SMP-Java-Gradle here (CCI stands for CircleCI, which I'm going to use next time, and SMP stands for SaMPle). You can use any name you like. In addition, Maven template is specified in Add .gitignore. GitHub - New Repository

Pull locally and launch VS Code

Pull the created repository to your local environment. For the environment in this article

git clone [email protected]:mfunaki/CCI-SMP-Java-Gradle.git

It will be like that. When you're done pulling, go to the directory where it was created (for example, cd CCI-SMP-Java-Gradle) and

code .

Start VS Code from the directory where your local repository is located. Menu ** Terminal ** → You can also start the terminal with ** new terminal ** (in the photo below, the host name of my local environment, MAYOCT-P73 is displayed). Local Repository

Move the development environment from local to container

Click the green > < at the bottom left to display the command palette and display the options related to Remote Development. Select ** Remote-Containers: Open Folder in Container ** from these. I will. Remote Development

You will be asked from which folder to open VS Code, so leave the current directory specified and press the ** Open ** button. Then you will be asked for the container environment (automatically generated and added), so select ** Java **. Java

Next, you will be asked for the Java version, ** 15 **, and then Maven, Gradle, Node.js, whichever you want to install, so select ** Install Maven ** here. Then VS Code is restarted, but the description ** Dev Container: Java ** is added to the green > < at the bottom left, indicating that the bash prompt on the terminal is also in the container. It changed to the notation. VSCode on Java Container

Subsequent work is in the container. If you look at the automatically generated .devcontainer/Dockerfile, you can see that your world is Microsoft-made

# See here for image contents:

# [Choice] Java version: 11, 15

# [Option] Install Maven
# [Option] Install Gradle
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "source /usr/local/sdkman/bin/ && sdk install maven \"${MAVEN_VERSION}\""; fi \
    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "source /usr/local/sdkman/bin/ && sdk install gradle \"${GRADLE_VERSION}\""; fi

# [Option] Install Node.js
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/ && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
#     && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/ && npm install -g <your-package-here>" 2>&1

Check the Java and Gradle (gradle) versions on the terminal. Versions (I don't know how the behavior changes when the value of ARG INSTALL_GRADLE =" false " in the Dockerfile is true/false.)

Create a sample in the repository (on the container)

We will create a sample using Building Java Applications Sample on the Gradle official website as an example.

Creating a project folder

Open a terminal on VSCode, create a project folder (demo) in it, and go to the project folder. cd demo

Run init task

Run gradle init to initialize the project.

--For Select type of project to generate, select 2: application. --For Select implementation language, use the default 3: Java, --For Split functionality across multiple subprojects, use the default of 2: no. --For Select build script DSL (select the domain-specific language (DSL) that writes the build script), use the default 1: Groovy. --For Select test framework, use the default 1: JUnit 4, --For Project name, enter the default demo, --For Source package, the default demo,

Specify each. gradle init

In addition, the directories and files generated under the demo directory are displayed as follows in VS Code Explorer. demo

Run application

Running ./gradlew run in the terminal will run the run task (the files needed to run Gradle will be downloaded to the local ~/.gradle/wrapper/dists folder) and ** Hello World !** is output. gradlew run

Bundle application

Running ./gradlew build in the terminal will run the build task. gradle build As a result, the following two files are generated.


Publish Build Scan

If you have a build problem, the information provided by Gradle to help you investigate is called Build Scan. To publish Build Scan, run ./gradlew build --scan in your terminal. Build Scan On the way

Publishing a build scan to requires accepting the Gradle Terms of Service defined at Do you accept these terms? (Publishing Build Scan to requires you to accept the Gradle Terms of Service defined at Do you accept the terms? )

If you agree, enter yes to proceed. Finally, the URL of Build Scan will be displayed, so if you enter the email address on the screen where you clicked the URL, you will receive an email, and if you click the URL in the email, you will be able to see Build Scan. Build Scan

at the end

The work on the container is actually done by mounting the local directory (git clone), so click the green > < at the bottom left and ** Remote- from the command palette. Select Containers: Reopen Locally **. Command Palette

Add, update, commit, and push to GitHub. If all goes well, you'll see the .devcontainer and demo directories on your GitHub repository. GitHub Next time, I'll talk about build and test automation using CircleCI. See you again. Goodbye.

Recommended Posts

Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a Java (Maven) project with VS Code and develop it on a Docker container
Workspace setting location when connecting remotely with VS Code and working on a Docker container
Build a Java project with Gradle
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Building a haskell environment with Docker + VS Code on Windows 10 Home
Create a Docker Image for redoc-cli and register it on Docker Hub
Starting with installing Docker on EC2 and running Yellowfin in a container
Create a program to post to Slack with GO and make it a container
Create a Lambda Container Image based on Java 15
Using Gradle with VS Code, build Java → run
Prepare a scraping environment with Docker and Java
Try debugging a Java program with VS Code
Build a Java development environment with VS Code
Connect with VS Code from a Windows client to Docker on another server
Getting started with Gradle (until you create a Java project and combine external libraries into one executable JAR)
[Note] Create a java environment from scratch with docker
Build Java development environment with WSL2 Docker VS Code
[Environment construction] Build a Java development environment with VS Code!
Create a private key / public key in CentOS8.2 and connect to SSH with VS Code
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
Run VS Code on Docker
Create a container image for arm64 of Kibana and register it in GitHub Container Registry. Start Elastic Stack with Docker Compose on Raspberry Pi 4 (64bit)
Docker management with VS Code
Create a VS Code Plugin.
Maybe it works! Create an image with Docker and share it!
[Docker] Build a site on Hugo and publish it on GitHub
Try Hello World using plain Java on a Docker container
A memo to start Java programming with VS Code (2020-04 version)
Create a Java and JavaScript team development environment (gradle environment construction)
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)
Easily convert Java application to Docker container with Jib ~ Build with gradle and register in local repository
Create a Vue3 environment with Docker!
Build Metabase with Docker on Lightsail and make it https with nginx
Summary of steps for developing in Docker container with VS Code
[Note] A story about changing Java build tools with VS Code
Java 15 implementation and VS Code preferences
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"
Create a high-performance enum with fields and methods like Java with JavaScript
Run React on a Docker container
How to create a new Gradle + Java + Jar project in Intellij 2016.03
Create a Java project using Eclipse
Java build with mac vs code
Create a flyway jar with maven and docker build (migrate) with docker-maven-plugin
Run PureScript on a Docker container
I tried deploying a Docker container on Lambda with Serverless Framework
Getting Started with Docker with VS Code
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
Create a Maven project with a command
[Gradle] Build a Java project with a configuration different from the convention
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
Access MySQL on a Docker container from a local (host OS) Java program
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
A memorandum when IME cannot be turned on with VS Code (Ubuntu 20.04)
[Java] Create a jar file with both compressed and uncompressed with the jar command
How to create a server executable JAR and WAR with Spring gradle
I wrote a Lambda function in Java and deployed it with SAM
Create a java web application development environment with docker for mac part2
[Java] Create and apply a slide master
Prepare Java development environment with VS Code
Link Java and C ++ code with SWIG