I use gradle java library plugin and maven publish plugin to create a jar file then publish it to a nexus repo. However, the generated jar file doesn't include the application.properties file under the src/main/resource path. I did some research and apparently gradle should add the files under src/main/resource path to the jar by default. so I have no idea why it's not added.
my project structure
src
--main
--java
--com.abc.bcd
--A.java
--B.java
--C.java
--resources
--application.properties
my build.gradle file is like this
/*
* 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"
}
}
the generated jar file now only includes java classes
com
--abc
--bcd
--A.class
--B.class
--C.class
META-INF
--MANIFEST.MF
--maven
--abc.bcd
--pom.xml