Maven profile with yaml

We have a multi-module maven web application that has a properties files for every one of them.Because of that it contains a total of 12 properties files.

We want to replace the properties to YAML properties so it will be only one config file separated by profiles.

We use maven profile to set specific properties environment. In the parent pom we set the profiles:

  <profiles>
    <profile>
        <id>playchannel</id>
        <properties>
            <produto>playchannel</produto>
            <build.profile.id>dev</build.profile.id>
        </properties>
        <modules>
            <module>core-jar</module>
            <module>playchannel-jar</module>
            <module>core-war</module>
            <module>playchannel-war</module>
        </modules>
    </profile>
    <profile>
        <id>playout</id>
        <properties>
            <produto>playout</produto>
            <build.profile.id>dev</build.profile.id>
        </properties>
        <modules>
            <module>core-jar</module>
            <module>playout-jar</module>
            <module>core-war</module>
            <module>playout-war</module>
        </modules>
    </profile>
    <profile>
        <id>default</id>
        <properties>
            <produto>playchannel e playout</produto>
            <build.profile.id>dev</build.profile.id>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>core-jar</module>
            <module>playchannel-jar</module>
            <module>playout-jar</module>
            <module>core-war</module>
            <module>playchannel-war</module>
            <module>playout-war</module>
        </modules>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <produto>playchannel e playout</produto>
            <build.profile.id>test</build.profile.id>
        </properties>
        <modules>
            <module>core-jar</module>
            <module>playchannel-jar</module>
            <module>playout-jar</module>
            <module>core-war</module>
            <module>playchannel-war</module>
            <module>playout-war</module>
        </modules>
    </profile>
</profiles>

And in the children poms we use filters:

 <filters>
        <filter>${project.basedir}/profiles/${build.profile.id}/config.properties</filter>
        <filter>${project.basedir}/profiles/${build.profile.id}/FileSyncConfig.properties</filter>
    </filters>

We have tested the yaml and in parent pom we use a maven plugin to spread application.yaml that we put in the root directory to resources folder of every module:

 <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-yml-main</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/..</directory>
                                    <includes>
                                        <include>application.yml</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

This is our Yaml Config class

@Configuration
public class YamlConfig {

    @Value("${config.tag.limit}")
    private int tagMaxQuantity;

    @Value("${config.videoExtensions}")
    private String videoExtensions;

    @Value("${config.miscelaneousImageExtensions}")
    private String miscelaneousImageExtensions;

    @Value("${config.misc}")
    private String miscelaneousPath;

    @Value("${config.entrada}")
    private String mediaRoot;

    @Value("${config.saida}")
    private String exportRoot;

    @Value("${config.path.ffprobe}")
    private String pathFfprobe;

    @Value("${file.sync.repository.root}")
    private String fileSyncRepositoryRoot;

    @Value("${file.sync.repository.torrent}")
    private String fileSyncRepositoryTorrent;

    @Value("${file.sync.repository.excluidos}")
    private String fileSyncRepositoryExcluidos;

    @Value("${file.sync.exibidores.root}")
    private String fileSyncExibidoresRoot;

    @Value("${file.sync.exibidores.multimedia}")
    private String fileSyncExibidoresMultimedia;

    @Value("${file.sync.exibidores.planilha}")
    private String fileSyncExibidoresPlanilha;

    @Value("${file.sync.temp}")
    private String fileSyncTemp;

    @Value("${file.sync.swfFile.sd}")
    private String fileSyncSwfFileSd;

    @Value("${file.sync.swfFile.hd}")
    private String fileSyncSwfFileHd;

    @Bean
    public static PropertySourcesPlaceholderConfigurer ymlProperties() {
        PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        yaml.setResources(new ClassPathResource("application.yml"));
        propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());

        return propertySourcesPlaceholderConfigurer;
    }

    public int getTagMaxQuantity() {
        return tagMaxQuantity;
    }

    public void setTagMaxQuantity(int tagMaxQuantity) {
        this.tagMaxQuantity = tagMaxQuantity;
    }

    public String getVideoExtensions() {
        return videoExtensions;
    }

    public void setVideoExtensions(String videoExtensions) {
        this.videoExtensions = videoExtensions;
    }

    public String getMiscelaneousImageExtensions() {
        return miscelaneousImageExtensions;
    }

    public void setMiscelaneousImageExtensions(String miscelaneousImageExtensions) {
        this.miscelaneousImageExtensions = miscelaneousImageExtensions;
    }

    public String getFileSyncRepositoryRoot() {
        return fileSyncRepositoryRoot;
    }

    public void setFileSyncRepositoryRoot(String fileSyncRepositoryRoot) {
        this.fileSyncRepositoryRoot = fileSyncRepositoryRoot;
    }

    public String getFileSyncRepositoryTorrent() {
        return fileSyncRepositoryTorrent;
    }

    public void setFileSyncRepositoryTorrent(String fileSyncRepositoryTorrent) {
        this.fileSyncRepositoryTorrent = fileSyncRepositoryTorrent;
    }

    public String getFileSyncRepositoryExcluidos() {
        return fileSyncRepositoryExcluidos;
    }

    public void setFileSyncRepositoryExcluidos(String fileSyncRepositoryExcluidos) {
        this.fileSyncRepositoryExcluidos = fileSyncRepositoryExcluidos;
    }

    public String getFileSyncExibidoresRoot() {
        return fileSyncExibidoresRoot;
    }

    public void setFileSyncExibidoresRoot(String fileSyncExibidoresRoot) {
        this.fileSyncExibidoresRoot = fileSyncExibidoresRoot;
    }

    public String getFileSyncExibidoresMultimedia() {
        return fileSyncExibidoresMultimedia;
    }

    public void setFileSyncExibidoresMultimedia(String fileSyncExibidoresMultimedia) {
        this.fileSyncExibidoresMultimedia = fileSyncExibidoresMultimedia;
    }

    public String getFileSyncExibidoresPlanilha() {
        return fileSyncExibidoresPlanilha;
    }

    public void setFileSyncExibidoresPlanilha(String fileSyncExibidoresPlanilha) {
        this.fileSyncExibidoresPlanilha = fileSyncExibidoresPlanilha;
    }

    public String getFileSyncTemp() {
        return fileSyncTemp;
    }

    public void setFileSyncTemp(String fileSyncTemp) {
        this.fileSyncTemp = fileSyncTemp;
    }

    public String getFileSyncSwfFileSd() {
        return fileSyncSwfFileSd;
    }

    public void setFileSyncSwfFileSd(String fileSyncSwfFileSd) {
        this.fileSyncSwfFileSd = fileSyncSwfFileSd;
    }

    public String getFileSyncSwfFileHd() {
        return fileSyncSwfFileHd;
    }

    public void setFileSyncSwfFileHd(String fileSyncSwfFileHd) {
        this.fileSyncSwfFileHd = fileSyncSwfFileHd;
    }

    public String getMiscelaneousPath() {
        return miscelaneousPath;
    }

    public void setMiscelaneousPath(String miscelaneousPath) {
        this.miscelaneousPath = miscelaneousPath;
    }

    public String getMediaRoot() {
        return mediaRoot;
    }

    public void setMediaRoot(String mediaRoot) {
        this.mediaRoot = mediaRoot;
    }

    public String getExportRoot() {
        return exportRoot;
    }

    public void setExportRoot(String exportRoot) {
        this.exportRoot = exportRoot;
    }

    public String getPathFfprobe() {
        return pathFfprobe;
    }

    public void setPathFfprobe(String pathFfprobe) {
        this.pathFfprobe = pathFfprobe;
    }
}

And we start to replace the properties files to yaml. Everything works fine with one profile:

    foo: TesteYAMLraiz
config:
    colors: aliceblue,antiquewhite,aqua,beige,bisque,burlywood,chartreuse,cornflowerblue,cornsilk,darkgray,darkkhaki,darkmagenta,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkturquoise,deepskyblue,dodgerblue,firebrick,gainsboro,gold,goldenrod,greenyellow,honeydew,hotpink,indigo,ivory,khaki,lavender,lavenderblush,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightpink,lightsalmon,lightseagreen,lightskyblue,lightyellow,limegreen,linen,magenta,mediumaquamarine,mediumorchid,mediumpurple,mediumturquoise,navajowhite,oldlace,olive,orange,palegoldenrod,palegreen,paleturquoise,powderblue=======
    entrada: c:/MANAGER_PLAYCHANNEL/Entrada
    misc: \\server18/MANAGER/mmFiles/misc
    miscelaneousImageExtensions: jpg,jpeg
    mongodb:
        name: playmanager
    path:
        ffprobe: C:/MidiacentroFerramentas/FFMPEG/bin/ffprobe.exe
    report:
        url:
            exibithions: http://192.168.1.18:8081/solus-report-web/video/home
            exibithions.ancine: '#'
    saida: "////server18/MANAGER/Saida"
    schedule:
        cron: 0 0 1 * * *
    tag:
        limit: 100
    threadpool:
        corepoolsize: 2
        maxpoolsize: 10
        queueCapacity: 30
    videoExtensions: mxf,mp4,m4a,m4p,m4b,m4r,m4v,mov,qt,lxf,asf,wmv,dv,dif,ts,tsv,tsa,gxf,flv,f4v,avi,mkv,mk3d,webm
spring:
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: true
  datasource:
    url: jdbc:mysql://localhost:3306/manager_service?autoReconnect=true

The problem is that we have multiple profiles. So the question is if we can use the same structure for YAML. If we can use maven profile to work with yaml or we need to use spring profile only?And how to do that?

  • org.gradle.internal.event.ListenerNotificationException: Failed to notify build listener

    When we build our application using gradle, it is throwing exception below * Exception is: org.gradle.internal.event.ListenerNotificationException: Failed to notify build listener. at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:86)

    and Caused by: java.lang.OutOfMemoryError: Java heap space.

    how to resolve this error to have clean build...

  • Heroku launch maven project

    Hello i have an maven project with is deploy on Heroku but he don't run so i would like to know how run a maven project on heroku ?

    I try to do this :

    java $JAVA_OPTS -cp target/classes:target/dependency/* main
    

    But I have this error :

    Exception in thread "main" java.lang.NoClassDefFoundError: net/dv8tion/jda/core/hooks/ListenerAdapter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at main.main(main.java:3)
    Caused by: java.lang.ClassNotFoundException: net.dv8tion.jda.core.hooks.ListenerAdapter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    

    To develop i used Intellij

    My maven project : https://github.com/EscapeManOZK/BotDiscordMaven