A standardized Java development environment template using VS Code DevContainer and Google Cloud Workstations. Streamlines development setup with pre-configured tools and consistent environments across teams.
- Java 21 (Liberica JDK)
- VS Code DevContainer support
- Google Cloud Workstations integration
- Git hooks for automated code formatting
- Pre-configured development tools
- Ready-to-use development setup
- Visual Studio Code
- Docker Desktop
- VS Code Extension:
- Copy the .devcontainer directory
- Ensure Docker Desktop is running
- Open the project directory in VS Code
- VS Code will detect the
.devcontainerdirectory and prompt to reopen the project in container - Click "Reopen in Container" in the bottom-right corner or click the green button "><" in the bottom-left corner and select "Reopen in Container"
The development container provides:
- Pre-installed Java 21 (Liberica JDK)
- VS Code extensions for Java development
After container creation, the following setup is automatically performed:
- Installation of Google Java Formatter
- Configuration of Git Hooks
Note: Git configurations are automatically synchronized from the host machine to the container (Mac)
Open workstations/cloudbuild.yaml and modify the following variables:
_PROJECT_ID: Your GCP project ID_REPOSITORY_NAME: Your Artifact Registry repository name_IMAGE_NAME: Your Workstations image name_IMAGE_TAG: Your Workstations image version
Then run the following commands:
export PROJECT_ID={Your GCP project ID}
cd workstations
gcloud builds submit --config=cloudbuild.yaml --project=${PROJECT_ID}This will build and push a Docker image with pre-installed Java 21 environment to Artifact Registry.
Navigate to Google Cloud Workstations page, select Cluster Manager, and create a Workstation Cluster.
After creation is complete:
Next, select Workstation Configurations:
-
Basic Information
- Name:
config-spring - Select your created cluster
- Quick start: Disabled (recommended for lower costs)
- Name:
-
Labels and Tags
- Labels: Add labels to categorize and manage resources
- Tags: Add tags to categorize and manage resources
- Machine Configuration
- Series: Choose based on your needs:
- N2: Recommended for development
- E2: Cost-optimized general purpose workloads
- T2D: AMD-based alternative with good price/performance ratio
- Machine type: Select based on your development requirements:
- n2-standard-2 (2 vCPU, 8 GB memory): Light development
- n2-standard-4 (4 vCPU, 16 GB memory): Standard development
- n2-standard-8 (8 vCPU, 32 GB memory): Heavy development
- Zones: asia-east1-a and asia-east1-c
- Auto-sleep: After 2 hours of inactivity (recommended for cost savings)
- Series: Choose based on your needs:
Note: Cost estimate for n2-standard-4 (asia-east1)
- Hourly rate: $0.224904
- Daily usage: 9 hours
- Monthly working days: 20 days
- Monthly cost estimate: $0.224904 × 9 × 20 = ~$40.48
Cost saving tips:
- Use Auto-sleep feature
- Stop workstation when not in use
- Environment Settings
- Container image: Custom container image
- Container image URL:
asia-east1-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY_NAME}/${IMAGE_NAME}:${IMAGE_TAG} - Service account: Compute Engine default service account
- Storage: Create new empty persistent disk
- Disk type: Balanced
- Access Control
- Users and permissions: Users can create workstations through the console
- Add authorized users or groups as needed
- Keep Advanced options as default
Click CREATE to complete the configuration:
Navigate to the Workstations page:
Click CREATE WORKSTATION and configure the following:
Configure the following settings:
- Name: (e.g., w-samzhucn480th9v)
- Display Name: (e.g., sam)
- Configuration: Select your created configuration (e.g., config-spring)
After creation, your workstation will appear:
Start your workstation and click the Launch button to access it:
The environment comes pre-configured with Java 21, Google Java Format tool, and predefined extensions:
You can also enable Gemini Code Assistant to help with development:
Your development environment is now ready for Java development with all necessary tools and extensions installed.
Run the following command to install Git Hooks. This will automatically configure the pre-commit hook for Java code formatting:
curl -fsSL https://raw.githubusercontent.com/samzhu/java-dev-env-template/main/workstations/install-java-format-hooks.sh | bashSpring Boot CLI is pre-installed in the environment for quick project creation.
mkdir workspace && cd workspace
spring init --java-version=21 --dependencies=web,actuator sample-app.zip
unzip sample-app.zip -d sample-appAfter extraction, open the sample-app directory in VS Code to start developing your Spring Boot application.
Use spring init --list to view all available options:
- Dependencies: View all supported dependencies
- Java versions: Check supported Java versions
- Project types: See available project types
- Packaging options: JAR or WAR
- Language options: Java, Kotlin, or Groovy
You can type spring help to get more details spring help init.
Common usage examples:
# Create a Gradle project with Java
spring init --type=gradle-project \
--java-version=21 \
--dependencies=web,data-jpa \
my-gradle-app.zip
# Create a project with custom name and description
spring init --name=MyApp \
--description="My Spring Boot Application" \
--package=com.example.myapp \
custom-app.zip
# Common Spring Boot Dependencies
spring init --type=gradle-project \
--language=java \
--boot-version=3.4.1 \
--packaging=jar \
--java-version=21 \
--groupId=com.example \
--artifactId=demo \
--name=demo \
--description="Demo project for Spring Boot" \
--package-name=com.example.demo \
--dependencies=devtools,lombok,configuration-processor,docker-compose,web,oauth2-client,postgresql,data-jpa,batch,validation,actuator,sbom-cyclone-dx,otlp-metrics,cloud-resilience4j,cloud-feign,prometheus,distributed-tracing,testcontainers \
demo.zipCommon Dependencies Explained
- web: Web application development with Spring MVC and embedded Tomcat
- devtools: Development tools including automatic restart and live reload
- lombok: Annotation-based code generator to reduce boilerplate
- configuration-processor: Metadata generation for custom configuration properties
- docker-compose: Integration with Docker Compose for container orchestration
- oauth2-client: OAuth 2.0 client support for authentication
- postgresql: PostgreSQL JDBC driver and database connectivity
- data-jpa: JPA data persistence with Hibernate
- batch: Batch processing framework for enterprise applications
- validation: Bean validation using Hibernate Validator
- actuator: Production-ready features for monitoring and management
- sbom-cyclone-dx: CycloneDX SBOM format for software supply chain security
- otlp-metrics: OpenTelemetry protocol support for metrics export
- cloud-resilience4j: Circuit breaker and fault tolerance patterns
- cloud-feign: Declarative REST client with Netflix Feign
- prometheus: Prometheus metrics collection and monitoring
- distributed-tracing: Distributed tracing with OpenTelemetry
- testcontainers: Container-based integration testing framework














