Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khmarbaise/multienv-maven-plugin
multienv-maven-plugin
https://github.com/khmarbaise/multienv-maven-plugin
java maven maven-plugin
Last synced: 3 months ago
JSON representation
multienv-maven-plugin
- Host: GitHub
- URL: https://github.com/khmarbaise/multienv-maven-plugin
- Owner: khmarbaise
- License: apache-2.0
- Created: 2016-03-06T18:48:49.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T15:05:04.000Z (about 3 years ago)
- Last Synced: 2024-10-03T15:25:13.376Z (4 months ago)
- Topics: java, maven, maven-plugin
- Language: Java
- Homepage: https://khmarbaise.github.io/multienv-maven-plugin/
- Size: 1.02 MB
- Stars: 9
- Watchers: 5
- Forks: 8
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Multi Environment Maven Plugin
==============================[![Apache License, Version 2.0, January 2004][shield-license]][apache-license]
[![Build Status][build-status]][travis-ci]
[![Maven Central][shield-central]][maven-central]License
-------
[Apache License, Version 2.0, January 2004](http://www.apache.org/licenses/)Overview
--------There are several scenarios where you have different configurations for
different environments like dev, test, prod etc. (in real life there are
usually more environments than three.).Now you need to produce different artifacts for example war files for those
different environments. A combination of [maven-assembly-plugin and some
descriptors][blog-multiple-environments-i] will solve this. Also this
can be [enhanced for other things as well][blog-multiple-environments-ii].The problem becomes worse if you have more than two or three environments than the
[configuration][iterator-plugin] with
[maven-assembly-plugin][iterator-plugin-map] etc. became cumbersome.
This plugin will exactly handle such scenarios.The scenarios are the following. Producing artifacts which include the
configuration for each [environment](README.md#example-1): or artifacts which contain only the
[configuration](README.md#example-2): for the appropriate environment.Example 1
---------Let us assume you have several environments like `dev-01`, `dev-02`, `test-01`,
`test-02` and finally `prod`. We will make the situation simpler for this
example and assume having only a single module build which produces a
single `war` file as a result.The prerequisite to use the MultiEnv Maven Plugin is to create
a directory structure similar like the following:src
├── main
├── environments
├── dev-01
│ └── first.properties
├── dev-02
│ └── first.properties
├── test-01
│ └── first.properties
├── test-02
│ └── first.properties
└── prod
└── first.propertiesIn result the MultiEnv Maven Plugin will automatically create the
appropriate war files containing the configuration file `first.properties`
(just a single file for brevity in this example) which might contain some information like
the database connections url etc. for the appropriate environment.You can of course put several different files into the different environment
directories. It is also possible to create a directory structure under the appropriate
environment. This will also be packaged into the resulting artifact.The environment name (directory name `dev-01`, `dev-02`, `test-01` etc.) will
automatically being used as classifier for the appropriate artifact. So we
would get the following files after running MultiEnv Maven Plugin via
([assuming you have configured it correctly](README.md#how-to-configure)):```
mvn clean package
```* artifactId-version-dev-01.war
* artifactId-version-dev-02.war
* artifactId-version-test-01.war
* artifactId-version-test-02.war
* artifactId-version-prod.warIf you need to add a new environment this can simply being achieved by adding a
new directory under `environments` which might being called `qa-01` plus the
information you would like to configure and that's it. MultiEnv Maven
Plugin will automatically identify the new environment by searching in the
environment directory and producing an appropriate artifact out of it.Those above packages contain the original `war` file content as well
as the supplemental files/directories which have been given for the
appropriate environments.Example 2
---------In this example we would like to create configuration artifacts for
each environment.The configuration looks exactly the same in [Example 1](README.md#example-1)
except for the used goal. So you need to change the
goal from `environment` to `configuration` in the plugin configuration.
By using the:```
mvn clean package
```you will produce the following artifacts:
* artifactId-version-dev-01.jar
* artifactId-version-dev-02.jar
* artifactId-version-test-01.jar
* artifactId-version-test-02.jar
* artifactId-version-prod.jarAs you might already realized that those files are not `war` files. The
files are jar files which contain the configuration for each environment.How To Configure
----------------To configure MultiEnv Maven Plugin you simply add the following
to your pom file (we assume here a war file):``` xml
groupId
artifactId
0.1.0-SNAPSHOT
war
...
com.soebes.maven.plugins
multienv-maven-plugin
0.3.1
environment
```Filtering
---------Based on the given directory structure files like `first.properties` etc. will be
filtered before they are packaged into the resulting artifacts. This means you
can use things like `${project.version}` in your files or other self defined
properties.Document:
* Using filename/directory filtering ?
* Different files for different environmentsAdvantages
----------* Much more convenient
* less configuration.
* Dynamically add new environments
* No Profiles needed.TODO
----* MultiEnv Maven Plugin in a different maven project within multi module
build? How does that work?
* Overwriting of file which exist in the original artifact? How to handle?
* Produce an artifact only for a single environment?
`mvn -Dmultienv.environment=test-01 clean package`
Is this a good idea?
* Do filtering for each environment separately. So we could inject
the name of the environment. This can be used put the name of the
environment into the resulting files via filtering.[blog-multiple-environments-i]: http://blog.soebes.de/blog/2011/07/29/maven-configuration-for-multipe-environments/
[blog-multiple-environments-ii]: http://blog.soebes.de/blog/2011/08/11/maven-configuration-for-multipe-environments-ii/
[iterator-plugin]: http://khmarbaise.github.io/iterator-maven-plugin/
[iterator-plugin-map]: https://github.com/khmarbaise/iterator-maven-plugin/blob/master/src/it/mavenAssemblyPluginTest/pom.xml
[maven-central]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.soebes.maven.plugins%22%20a%3A%22multienv-maven-plugin%22
[apache-license]: http://www.apache.org/licenses/
[travis-ci]: https://travis-ci.org/khmarbaise/multienv-maven-plugin
[build-status]: https://travis-ci.org/khmarbaise/multienv-maven-plugin.svg?branch=master
[shield-central]: https://img.shields.io/maven-central/v/com.soebes.maven.plugins/multienv-maven-plugin.svg?label=Maven%20Central
[shield-license]: https://img.shields.io/github/license/khmarbaise/iterator-maven-plugin.svg?label=License