如何在Gradle中使用子模型设置弹簧启动



,所以我只是在玩(实验)gradle和spring-boot。

当我关注Hello World时,我很容易地完成项目运行,这让我开心。

现在我想拥有一个结构化的项目;为此,我正在使用Intellij社区(不确定是否相关)。我有以下结构。

/项目 - build.gradle -settings.gradle(仅包括服务)/项目/服务/ - build.gradle -settings.gradle(仅包括MyService)/项目/服务/MyServices - build.gradle

现在我可以共享一些我的build.gradle文件,但是我"尝试在互联网上找到随机的东西。我的问题是,春季启动类是在MyService上不可用的。MyService内的以下目录结构是标准java(/src/main/java)

我正在尝试将依赖项&如果可能的话,我的主要版本中的版本。有人可以指出我做错了什么。

目前,我只使用Gradle进行简单的Android开发工作。

/project/build.gradle

group 'nl.msegers.project'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

/project/services/build.gradle

group 'nl.msegers.project.services'
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
    }
}

/project/services/myservice/build.gradle

group 'nl.msegers.project.services.myservice'
version parent.version
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
    baseName = 'Navigation'
    version =  parent.version
}
repositories {
    mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

都有每个项目从根中继承依赖项,您可以在root项目上使用allprojects脚本块,例如:

allprojects {
            dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.+'
        ...
    }
}

我一直在搜寻一个小时左右的网络,以使这样的结构工作。同时,我也从头开始重建项目(尽管我没有太多代码)。

我的代码当前允许简单的Spring Boot Sub Project,而无需太多冗余配置,并且它们可以轻松地编译库项目,但是这可以使用一些工作。

我现在得到的是这样的结构。

/项目/项目/图书馆/项目/图书馆/模型/项目/服务//项目/服务/服务

使用唯一值得注意的build.gradle文件(其他文件几乎为空):

/project/services/

group 'nl.msegers.project.services'
version parent.version
buildscript {
    ext {
        springBootVersion = "1.5.2.RELEASE"
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
subprojects {
    buildscript {
        ext {
            springBootVersion = "1.5.2.RELEASE"
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'

    dependencies {
        compile("org.springframework.boot:spring-boot-starter-web") {
            exclude module: "spring-boot-starter-tomcat"
        }
        compile("org.springframework.boot:spring-boot-starter-jetty")
        compile("org.springframework.boot:spring-boot-starter-actuator")
        compile project(':Libraries:Models')
        testCompile 'junit:junit:4.12'
    }
    task wrapper(type: Wrapper) {
        gradleVersion = '3.1'
    }
}

/project/services/myService

group 'nl.msegers.project.services.myservice'
version parent.version
jar {
    baseName = 'myservice'
    version =  parent.version
}
repositories {
    mavenCentral()
}

最新更新