This is a Maven Plugin which helps to generate java *.properties from *.yml (www.yaml.org).
1.3
Building the same artifact for different environments (staging
, development
, production
...) has always been an annoyance. Developer need to do maintainance multiple .properties files (as given tree bellow). Actually, they have a few different values, such as : connection.url
, connection.usname
, connection.pwd
...
Maven Profile plugin is a great tool to help when giving you an ability to do maintain your files, see Maven Profile guide!. In short, your files will be in a tree like bellow
├── resources
│ ├── dev
│ │ ├── log4j.properties
│ │ └── appplication.properties
│ └── local
│ ├── log4j.properties
│ └── application.properties
This is actual annoying if you have so many many environments and many many many properties need your maintenance (like my sample.properties
- soure code).
Define all properties for all environments in a YAML format (*.yml) like bellow
#Local env
local:
spring.profiles.active: ${spring.profile}
webapp.resource.location: /assets/
db:
jdbcUrl: jdbc:pgsql://localhost:5432/bizi-app
user: postgres
password: P@ssw0rd
driverClass: com.impossibl.postgres.jdbc.PGDriver
pool.maxSize: 5
base:
url: http://sample.com/sample-app/
adminTool.url: http://localhost:9090/
bizi.admin.api.root.url: http://localhost:9090/api/%s
redis.expire.time.min: 30
core.encryptor.passphrase: 6jNugJnQ
#Staging env
staging:
db:
user: bizi
password: password
base:
url: http://sample.com/sample-app/
adminTool.url: http://sample.com/sample-api/
bizi.admin.api.root.url: http://sample.com/sample-api/api/%s
The given example is to generate prod
from dev
.
<build>
<plugins>
<plugin>
<groupId>com.github.phuonghuynh</groupId>
<artifactId>yml2prop</artifactId>
<version>1.3</version>
<configuration>
<sourceYaml>${basedir}/src/main/resources/test.yml</sourceYaml>
<entries>
<entry>dev</entry>
<entry>prod</entry>
</entries>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
To run this plugin:
mvn yml2prop:run
And sample result like this (for prod
environment)
#Generated by Yml2Prop plugin.
#Sat Dec 19 21:42:38 ICT 2015
base.adminTool.url=http\://localhost\:9090/
base.url=http\://52.26.123.153\:8080/bizi-webtool/
bizi.admin.api.root.url=http\://localhost\:9090/api/%s
core.encryptor.passphrase=6jNugJnQ
db.driverClass=com.impossibl.postgres.jdbc.PGDriver
db.jdbcUrl=jdbc\:pgsql\://localhost\:5432/bizi-app
db.password=P@ssw0rd
db.pool.maxSize=5
db.user=postgres
redis.expire.time.min=30
spring.profiles.active=${spring.profile}
webapp.resource.location=/assets/
sourceYaml
: String - source path of your yaml fileentries
: Array of Strings - array of names that will be used to extracted to *.properties, ex: dev, prod, staging...destProp
: String - destination path of your properties file
Please fell free to contribute.