Извлечение пружинных стартеров загрузки в отдельный JAR - PullRequest
0 голосов
/ 21 сентября 2019

То, что я пытаюсь сделать, это извлечь все стартовые пружинные загрузчики в отдельное приложение, упаковать их все в один JAR (используя плагин gradle shadow) и затем развернуть его в локальном хранилище артефактов Nexus, такЯ могу импортировать его и все его зависимости в мое приложение весенней загрузки.

Вот сборка build.gradle приложения, содержащего стартовые загрузочные пружины:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "http://localhost:8081/repository/testowe/"
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

subprojects {
    apply plugin: 'java-library'
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'com.github.johnrengelman.shadow'
    apply plugin: 'maven-publish'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'org.springframework.boot'

    version = '1.0'
    sourceCompatibility = 1.11

    jar { enabled = true }
    shadowJar { classifier(null) }

    repositories {
        jcenter()
        mavenCentral()
        maven {
            url "http://localhost:8081/repository/testowe/"
            credentials {
                username 'admin'
                password 'admin123'
            }
        }
    }

    publishing {
        publications {
            shadow(MavenPublication) { publication ->
                project.shadow.component(publication)
            }
        }
        repositories {
            maven {
                url "http://localhost:8081/repository/testowe/"
                credentials {
                    username 'admin'
                    password 'admin123'
                }
            }
        }
    }

    dependencies {
        compile('org.springframework.boot:spring-boot-starter-web') {
            transitive = true
        }
        compile('org.springframework.boot:spring-boot-starter-actuator') {
            transitive = true
        }
        compile('org.springframework.boot:spring-boot-starter-data-jpa') {
            transitive = true
        }
        compile('org.springframework.boot:spring-boot-starter-security') {
            transitive = true
        }
        compile('org.springframework.boot:spring-boot-starter-test') {
            transitive = true
        }

    }
}

Вот сборка build.gradleSpring-Boot-приложения, которое я хочу запустить со всеми зависимостями Spring-Boot-Starter, поступающими из встроенного JAR-файла:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 11

repositories {
    mavenCentral()
    maven {
        url "http://localhost:8081/repository/testowe/"
        credentials {
            username 'admin'
            password 'admin123'
        }
    }
}

dependencies {
//    When I'm running app with starters placed here everything works fine
//    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
//    implementation('org.springframework.boot:spring-boot-starter-security')
//    implementation('org.springframework.boot:spring-boot-starter-test')
//    implementation('org.springframework.boot:spring-boot-starter-web')

//    When I'm trying to run it with my JAR it doesn't work
    implementation("pl.mplan:web-common:1.0")

    compile group: 'org.javassist', name: 'javassist', version: '3.23.2-GA'
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'

    runtimeOnly('org.postgresql:postgresql')
    compileOnly('org.projectlombok:lombok')
    testImplementation('org.springframework.boot:spring-boot-starter-test')

    compile("com.querydsl:querydsl-core:4.2.1")
    compile("com.querydsl:querydsl-jpa:4.2.1")
    compile("com.querydsl:querydsl-apt:4.2.1:jpa")

}

compileJava {
    options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/generated/java")
}

idea {
    module {
        sourceDirs += file("$projectDir/generated/java")
    }
}

Когда я пытаюсь запустить приложение с Gradle bootRun, вот что я получаю:

17:55:32.169 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'objectPostProcessor': [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration]
17:55:32.169 [main] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy() on bean with name 'objectPostProcessor'
17:55:32.175 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
    at pl.mplan.brew.it.BrewItBackendApplication.main(BrewItBackendApplication.java:12)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152)
    ... 8 common frames omitted

(я использую Gradle 4.8 и плагин Shadow 4.0.4)

Есть идеи, как это исправить?Заранее спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...