Git Product home page Git Product logo

java-in-docker's Introduction

Run a Java Project directly in a docker compose context. This is intended to be used in conjunction with gradle build --continuously and the Spring Boot Developer Tools, resulting in a smooth developer experience where the application is continuously built and reloaded.

Minimal Configuration

docker-compose.yml:

services:
  my-application:
    image: 'my-application' # or through build
    ports:
      - 8080:8080
      - 5005:5005

Of course, you will likely have many more services, like your database. These all can still communicate with the application being run via gradle runInDocker.

build.gradle:

plugins {
  id 'java'
  id 'de.mdguenther.gradle.java-in-docker' version '0.0.3'
}

javaInDocker {
  serviceName = 'my-application'
}

Only the plugin itself and javaInDocker.serviceName need to be configured, but more options are available (see below).

Running

Run in separate terminals (or via your favorite IDE):

  • ./gradlew build --continuously
  • ./gradlew runInDocker

Once you are done developing you can simply:

  • ./gradlew stopService
  • docker compose up -d my-application

Configuration

  • javaInDocker.serviceName the name of the service in the docker-compose.yml that is to be replaced.
  • javaInDocker.dockerComposeFile (default: docker-compose.yml) the path to the docker compose file relative to the project directory.
  • javaInDocker.containerName (default: ${javaInDocker.serviceName}) the name of the container. Any containers with this name are removed before the javaInDocker task is run.
  • javaInDocker.additionalDockerRunArgs (default: --service-ports) additional arguments passed via docker compose run.
  • javaInDocker.additionalJavaArgs (default: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 for Java remote debugging on port 5005) additional arguments passed to the java executable.

All in all the commandline executed by the task runInDocker should look like this:

docker compose run \
  --rm \
  ${javaInDocker.additionalDockerRunArgs} \
  -v "build:/build" \
  -v "~/.gradle:/gradle" \
  run "${javaInDocker.serviceName}" \
  java \
  ${javaInDocker.additionalJavaArgs} \
  -cp "/build/classes/java:/build/resources:${classpath}" \
  "${mainClassName}"

java-in-docker's People

Contributors

maxdavidguenther avatar

Stargazers

Kevin Krummenauer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.