Code Monkey home page Code Monkey logo

yml2prop's Introduction

YAML TO JAVA PROPERTIES MAVEN PLUGIN

This is a Maven Plugin which helps to generate java *.properties from *.yml (www.yaml.org).

Current version

1.3

Issue of do maintain java *.properties

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).

Example configuration

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/

Configuration parameters:

  • sourceYaml: String - source path of your yaml file
  • entries: 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.

yml2prop's People

Contributors

phuonghuynh avatar niromon 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.