{"id":13416528,"url":"https://github.com/spotify/dockerfile-maven","last_synced_at":"2025-09-29T01:30:37.603Z","repository":{"id":37396711,"uuid":"54030871","full_name":"spotify/dockerfile-maven","owner":"spotify","description":"MATURE: A set of Maven tools for dealing with Dockerfiles","archived":true,"fork":false,"pushed_at":"2022-02-01T13:43:18.000Z","size":257,"stargazers_count":2734,"open_issues_count":33,"forks_count":490,"subscribers_count":132,"default_branch":"master","last_synced_at":"2024-04-14T05:11:34.124Z","etag":null,"topics":["docker","java","maven"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spotify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-16T12:42:37.000Z","updated_at":"2024-04-13T15:16:43.000Z","dependencies_parsed_at":"2022-07-15T21:17:12.022Z","dependency_job_id":null,"html_url":"https://github.com/spotify/dockerfile-maven","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdockerfile-maven","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdockerfile-maven/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdockerfile-maven/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spotify%2Fdockerfile-maven/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spotify","download_url":"https://codeload.github.com/spotify/dockerfile-maven/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234579583,"owners_count":18855636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","java","maven"],"created_at":"2024-07-30T21:01:00.245Z","updated_at":"2025-09-29T01:30:37.258Z","avatar_url":"https://github.com/spotify.png","language":"Java","readme":"# Dockerfile Maven\n\n[![Build Status](https://travis-ci.com/spotify/dockerfile-maven.svg?branch=master)](https://travis-ci.com/spotify/dockerfile-maven)\n[![Maven Central](https://img.shields.io/maven-central/v/com.spotify/dockerfile-maven.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.spotify%22%20dockerfile-maven)\n[![License](https://img.shields.io/github/license/spotify/dockerfile-maven.svg)](LICENSE)\n\n## Status: mature\n\n**At this point, we're not developing or accepting new features or even fixing non-critical bugs.**\n\nThis Maven plugin integrates Maven with Docker.\n\nThe design goals are:\n\n  - Don't do anything fancy.  `Dockerfile`s are how you build\n    Docker projects; that's what this plugin uses.  They are\n    mandatory.\n  - Make the Docker build process integrate with the Maven build\n    process.  If you bind the default phases, when you type `mvn\n    package`, you get a Docker image.  When you type `mvn deploy`,\n    your image gets pushed.\n  - Make the goals remember what you are doing.  You can type `mvn\n    dockerfile:build` and later `mvn dockerfile:tag` and later `mvn\n    dockerfile:push` without problems.  This also eliminates the need\n    for something like `mvn dockerfile:build -DalsoPush`; instead you\n    can just say `mvn dockerfile:build dockerfile:push`.\n  - Integrate with the Maven build reactor.  You can depend on the\n    Docker image of one project in another project, and Maven will\n    build the projects in the correct order.  This is useful when you\n    want to run integration tests involving multiple services.\n\nThis project adheres to the [Open Code of Conduct][code-of-conduct].\nBy participating, you are expected to honor this code.\n\nSee the [changelog for a list of releases][changelog]\n\n[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md\n[changelog]: CHANGELOG.md\n\n## Set-up\n\nThis plugin requires Java 7 or later and Apache Maven 3 or later (dockerfile-maven-plugin \u003c=1.4.6 needs\nMaven \u003e= 3, and for other cases, Maven \u003e= 3.5.2). To run the integration tests or to use the plugin in practice, a working\nDocker set-up is needed.\n\n## Example\n\nFor more examples, see the [integration test](./plugin/src/it) directory.\n\nIn particular, the [advanced](./plugin/src/it/advanced) test showcases a\nfull service consisting of two micro-services that are integration\ntested using `helios-testing`.\n\nThis configures the actual plugin to build your image with `mvn\npackage` and push it with `mvn deploy`.  Of course you can also say\n`mvn dockerfile:build` explicitly.\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n  \u003cartifactId\u003edockerfile-maven-plugin\u003c/artifactId\u003e\n  \u003cversion\u003e${dockerfile-maven-version}\u003c/version\u003e\n  \u003cexecutions\u003e\n    \u003cexecution\u003e\n      \u003cid\u003edefault\u003c/id\u003e\n      \u003cgoals\u003e\n        \u003cgoal\u003ebuild\u003c/goal\u003e\n        \u003cgoal\u003epush\u003c/goal\u003e\n      \u003c/goals\u003e\n    \u003c/execution\u003e\n  \u003c/executions\u003e\n  \u003cconfiguration\u003e\n    \u003crepository\u003espotify/foobar\u003c/repository\u003e\n    \u003ctag\u003e${project.version}\u003c/tag\u003e\n    \u003cbuildArgs\u003e\n      \u003cJAR_FILE\u003e${project.build.finalName}.jar\u003c/JAR_FILE\u003e\n    \u003c/buildArgs\u003e\n  \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\nA corresponding `Dockerfile` could look like:\n\n```\nFROM openjdk:8-jre\nMAINTAINER David Flemström \u003cdflemstr@spotify.com\u003e\n\nENTRYPOINT [\"/usr/bin/java\", \"-jar\", \"/usr/share/myservice/myservice.jar\"]\n\n# Add Maven dependencies (not shaded into the artifact; Docker-cached)\nADD target/lib           /usr/share/myservice/lib\n# Add the service itself\nARG JAR_FILE\nADD target/${JAR_FILE} /usr/share/myservice/myservice.jar\n```\n\n**Important note**\n\nThe most Maven-ish way to reference the build artifact would probably\nbe to use the `project.build.directory` variable for referencing the\n'target'-directory. However, this results in an absolute path, which\nis not supported by the ADD command in the Dockerfile. Any such source\nmust be inside the *context* of the Docker build and therefor must be\nreferenced by a *relative path*. See https://github.com/spotify/dockerfile-maven/issues/101\n\n*Do **not** use `${project.build.directory}` as a way to reference your\nbuild directory.*\n\n## What does it give me?\n\nThere are many advantages to using this plugin for your builds.\n\n### Faster build times\n\nThis plugin lets you leverage Docker cache more consistently, vastly\nspeeding up your builds by letting you cache Maven dependencies in\nyour image.  It also encourages avoiding the `maven-shade-plugin`,\nwhich also greatly speeds up builds.\n\n### Consistent build lifecycle\n\nYou no longer have to say something like:\n\n    mvn package\n    mvn dockerfile:build\n    mvn verify\n    mvn dockerfile:push\n    mvn deploy\n\nInstead, it is simply enough to say:\n\n    mvn deploy\n\nWith the basic configuration, this will make sure that the image is\nbuilt and pushed at the correct times.\n\n### Depend on Docker images of other services\n\nYou can depend on the Docker information of another project, because\nthis plugin attaches project metadata when it builds Docker images.\nSimply add this information to any project:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n  \u003cartifactId\u003efoobar\u003c/artifactId\u003e\n  \u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n  \u003ctype\u003edocker-info\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\nNow, you can read information about the Docker image of the project\nthat you depended on:\n\n```java\nString imageName = getResource(\"META-INF/docker/com.spotify/foobar/image-name\");\n```\n\nThis is great for an integration test where you want the latest\nversion of another project's Docker image.\n\nNote that you have to register a Maven extension in your POM (or a\nparent POM) in order for the `docker-info` type to be supported:\n\n```xml\n\u003cbuild\u003e\n  \u003cextensions\u003e\n    \u003cextension\u003e\n      \u003cgroupId\u003ecom.spotify\u003c/groupId\u003e\n      \u003cartifactId\u003edockerfile-maven-extension\u003c/artifactId\u003e\n      \u003cversion\u003e${version}\u003c/version\u003e\n    \u003c/extension\u003e\n  \u003c/extensions\u003e\n\u003c/build\u003e\n```\n\n## Use other Docker tools that rely on Dockerfiles\n\nYour project(s) look like so:\n\n```\na/\n  Dockerfile\n  pom.xml\nb/\n  Dockerfile\n  pom.xml\n```\n\nYou can now use these projects with Fig or docker-compose or some\nother system that works with Dockerfiles.  For example, a\n`docker-compose.yml` might look like:\n\n```yaml\nservice-a:\n  build: a/\n  ports:\n  - '80'\n\nservice-b:\n  build: b/\n  links:\n  - service-a\n```\n\nNow, `docker-compose up` and `docker-compose build` will work as\nexpected.\n\n## Usage\n\nSee [usage docs](https://github.com/spotify/dockerfile-maven/blob/master/docs/usage.md).\n\n## Authentication\n\nSee [authentication docs](https://github.com/spotify/dockerfile-maven/blob/master/docs/authentication.md).\n\n## Releasing\n\nTo cut the Maven release:\n\n```\nmvn clean [-B -Dinvoker.skip -DskipTests -Darguments='-Dinvoker.skip -DskipTests'] \\\n  -Dgpg.keyname=\u003ckey ID used for signing artifacts\u003e \\\n  release:clean release:prepare release:perform\n```\n\nWe use [`gren`](https://github.com/github-tools/github-release-notes#installation) to create Releases in Github:\n\n```\ngren release\n```","funding_links":[],"categories":["Development with Docker","Java","maven","容器化工具"],"sub_categories":["API Client"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fdockerfile-maven","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspotify%2Fdockerfile-maven","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspotify%2Fdockerfile-maven/lists"}