我的主要模块与设置。格拉德尔:
allprojects {
buildDir = file("${rootDir}/build")
group = 'com.example'
version = "0.1.1"
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
}
背景格拉德尔
rootProject.name = 'test-application'
include 'bootApplication'
include 'eventListener'
project(":eventListener").projectDir = file("C:/examples/eventListener")
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group 'com.example.bootApplication'
version = "0.1.1"
sourceCompatibility = '11'
targetCompatibility = '11'
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
bootJar {
baseName("bootApplication")
}
jar {
enabled = true
}
dependencies {
compile project(":eventListnere")
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.springfox:springfox-swagger2:+'
implementation 'io.springfox:springfox-swagger-ui:+'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
我的听众:
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'`enter code here`
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group 'com.example.eventlistener'
version '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
targetCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
ext {
spring_boot_version = '2.2.1.RELEASE'
}
implementation "org.springframework.boot:spring-boot-starter:$spring_boot_version"
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
testImplementation "org.springframework.boot:spring-boot-starter-test:$spring_boot_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar.enabled = true
当我运行我的bootApplication主类时,它会在根构建目录中创建一个eventlistener-. jar文件。但是eventlistener模块没有检查资源文件夹,我猜它没有看到引导应用上下文。也许它应该被收集到一个jar文件?看起来我在gradle构建文件中遗漏了一些东西。
我会在前面加上一句我不知道下面的东西是否是你问题的真正原因。但是无论如何,您都应该改变一些与jar配置相关的事情。
SpringBootGradle插件用于从项目中创建一个胖jar。默认情况下,它禁用正常的jar
任务。
您正在通过jar.enabled=true
重新启用正常的jar任务,这很好。但是你也需要给它另一个名字,否则一个会覆盖另一个。例如,对于您的eventListener
项目,您可以这样做:
// eventListener/build.gradle
bootJar {
classifier = 'boot'
}
// eventListener/build.gradle
plugins {
// id 'org.springframework.boot' version '2.2.1.RELEASE'`enter code here` <-- Remove this
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
您仍然可以在项目中使用Spring Boot启动器,您只是不需要重新打包jar的插件。
同样的事情也适用于您的bootApplication
项目:您都在尝试创建一个fat可执行jar,同时创建一个普通jar。一个将覆盖另一个。在这种情况下,您可能不需要普通的jar,因此应该再次禁用jar
任务:
// eventListener/build.gradle
// jar.enabled = true <-- Remove this
最后,将compileproject(“:eventListnere”)
替换为implementation project(“:eventListener”)
,将testCompile
替换为testImplementation
,以避免一些弃用警告。maven
插件也被弃用,取而代之的是maven发布
。您可能还可以摆脱mavenLocal()
,除非您正在与本地Maven项目集成,而这些项目是您自己用mvn install
构建的。
eventListener
,如果正确地打包为一个普通的jar在bootApplication
的胖jar中,应该能够访问它自己的资源
文件夹中的资源以及来自bootApplication
的资源当你运行后者时。
问题内容: 我试图使用Dagger在正在构建的应用程序上进行依赖注入,当我拥有一个程序包的模块(取决于注入器(可能是另一个模块)提供的值)时,在构造适当的DAG时遇到了麻烦。 如果我有一个用于配置变量的简单模块(例如,我可能想换成测试环境) 而另一个模块依赖于它,例如 我尝试在构造函数中引导注入的行失败,并且它抱怨我没有在适当的模块中指定显式行。 通过反复试验,我发现如果在行中添加,这种情况就消失
问题内容: 我已使用以下命令“ go mod init database”在“数据库”文件夹中的“ GOPATH”之外创建了个人使用的模块库,但我不知道: 如何在其他模块中使用/ 导入 该模块? 操作系统: Windows 7 ,Go: v1.11 问题答案: 最简单,可行的现成解决方案是将您的包/模块放入VCS(例如github.com),因此其他包(在其他模块内部)可以通过导入来简单地引用它:
新建一个类,名为UserModule, package为net.wendal.nutzbook.module 配置Ioc相关注解及属性,即IocBean,Inject和Dao属性,哦哦,还有At 完成的后的代码如下 package net.wendal.nutzbook.module; import org.nutz.dao.Dao; import org.nutz.ioc.loader.ann
我有一个多模块梯度构建。我想使用root为一个模块执行目标。例如: