0
votes

In my project I'm using activeMQ artemis and Spring Boot. The application should be executed as an Apache Commons Daemon service. I'd like to use my custom launcher in this project.

The project has the following Gradle configuration:

buildscript {

    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url 'https://repo.spring.io/libs-snapshot' }
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7")
    }
}

plugins {
  id "org.sonarqube" version "2.6.1"
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'

ext {    
    commonsDaemonVersion = '1.1.0'
    artemis = '2.4.0'
}

dependencies {

    compile("org.apache.activemq:artemis-server:${artemis}")
    compile("org.apache.activemq:artemis-core-client:${artemis}")

    compile("commons-daemon:commons-daemon:${commonsDaemonVersion}")
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
}

Because I'm using activeMQ artemis, I can't use the Spring Boot Plugin's 1.5.x version, because its dependency management module downgrades apache activeMQ automatically to version 1.5.5. Because this project has to be executed as an Apache Commons Daemon Service, I have to use my custom Spring Boot launcher, which makes it possible to have a static launcher and classloader. These two help me to stop the already running service.

I tried the following setup to add my custom launcher to the generated jar-file with the following setup. However, that isn't the right way to do it, because I have to add my launcher's class name manually to the manifest file.

buildscript {

    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url 'https://repo.spring.io/libs-snapshot' }
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7")
    }
}


plugins {
  id "org.sonarqube" version "2.6.1"
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'

ext {
    commonsDaemonVersion = '1.1.0'
    artemis = '2.4.0'
}

configurations {
    launcher
}

dependencies {

    compile("org.apache.activemq:artemis-server:${artemis}")
    compile("org.apache.activemq:artemis-core-client:${artemis}")

    compile("commons-daemon:commons-daemon:${commonsDaemonVersion}")

    launcher("com.mycompany.springboot.launcher:my-custom-launcher:0.1.0-RELEASE")
}   

bootJar {

    from project.configurations.launcher.each {
        from(zipTree(it))
    }


    manifest {
        attributes 'Main-Class': 'com.mycompany.springboot.launcher.CustomLauncher'
    }

}

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
}

In version 1.5.x I could just use the following option to add my launcher configuration:

springBoot  {
    layoutFactory = new com.mycompany.springboot.launcher.CustomLauncherFactory()
}

Is there any setup, which I could use to add my custom Launcher with Spring Boot Gradle Plugin 2.x or do I have to use any workarounds here?

1
I found a solution to force Spring Dependency manager to load artemis 2.4.0 using the idea described here I added the following line to my build.gradle file: ext['artemis.version'] = '2.4.0' which makes it possible to use Spring Boot Gradle Plugin's 1.5.10 in my project (because I can use the proper artemis version, which won't be downgraded to 1.5.5). That means, I can simply use springBoot's layoutFactory setting as well.l_mcqueen

1 Answers

0
votes

I would suggest to look into using Spring Boot starter for Artemis spring-boot-starter-artemis. It should spin up embedded server without any friction.