gradle Java库插件不会将src / main / resources下的文件放入jar文件

时间:2019-01-15 12:30:39

标签: java gradle

我使用gradle java library pluginmaven publish plugin创建一个jar文件,然后将其发布到一个联系仓库中。但是,生成的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

0 个答案:

没有答案