java - gradle java library plugin不会将src/main/resources下的文件放到jar文件中
问题描述
我使用gradle java library plugin
andmaven publish plugin
创建一个 jar 文件,然后将其发布到一个 nexus 存储库。但是,生成的 jar 文件不包含该路径application.properties
下的文件。src/main/resource
我做了一些研究,显然 gradle 应该src/main/resource
默认将路径下的文件添加到 jar 中。所以我不知道为什么不添加它。
我的项目结构
src
--main
--java
--com.abc.bcd
--A.java
--B.java
--C.java
--resources
--application.properties
我的 build.gradle 文件是这样的
/*
* This file was generated by the Gradle 'init' task.
*/
apply plugin: 'java-library'
apply plugin: 'maven-publish'
repositories {
mavenCentral()
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
classifier = 'sources'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation 'com.google.guava:guava:27.0-jre'
api 'org.springframework.boot:spring-boot-starter-webflux:2.1.2.RELEASE'
testImplementation "org.assertj:assertj-core:3.11.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
testImplementation "com.github.tomakehurst:wiremock-standalone:2.19.0"
testImplementation "org.junit.platform:junit-platform-surefire-provider:1.3.2"
testImplementation "org.junit.platform:junit-platform-runner:1.3.2"
testImplementation "ru.lanwen.wiremock:wiremock-junit5:1.2.0"
}
group = 'com.abc.bcd'
version = '0.0.1'
publishing {
publications {
metrics(MavenPublication) {
from components.java
artifact sourcesJar
}
}
repositories {
maven {
credentials {
username = "${nexus_user}"
password = "${nexus_pass}"
}
url 'https://nexus.abc.io/repository/bcd-shared/content/repositories/snapshots'
}
}
}
jar {
into("META-INF/maven/$project.group/$project.name") {
from { generatePomFileForMetricsPublication }
rename ".*", "pom.xml"
}
}
生成的 jar 文件现在只包含 java 类
com
--abc
--bcd
--A.class
--B.class
--C.class
META-INF
--MANIFEST.MF
--maven
--abc.bcd
--pom.xml
解决方案
推荐阅读
- c# - 切换到开发模式
- flutter - 当我在颤振中应用计算按钮时,如何返回当前下拉列表的结果?
- c - 使用 fscanf 扫描文件后结果不正确
- react-native - React native:如果功能组件未默认导出,如何导入
- java - 如何在pdfbox中添加卢比符号
- javascript - 转换猫鼬对象时toObject不是函数错误
- javascript - 如何遍历对象数组以查找用户的 id?
- python - 使用 pygame 在 cx_Freeze 中包含整个文件夹
- firebase - 如果在其他设备上验证,Firebase 会将匿名 UID 链接到电子邮件验证
- swift - SwiftUI 播放 Lottie 动画