Gradle构建一个空的Jar文件。

huangapple go评论59阅读模式
英文:

Gradle Builds an Empty Jar File

问题

我使用 gradle init 将项目从 Maven 转换为 Gradle,并在更新依赖后进行了操作。gradle test 如预期般工作。然而,当我运行 gradle build 时,生成的 JAR 文件完全为空。

我尝试调整源设置以使其生效,但似乎并未解决问题。据我所知,目录结构与 Gradle 期望的相匹配,一切都嵌套在 src/main/groovy 中。

该项目的完整代码可在Github上找到

通常是什么原因导致构建中没有添加任何文件?除了 gradle init 创建的内容之外,是否还需要添加其他配置?

Gradle 构建文件:

plugins {
    id 'java'
    id 'maven-publish'
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.5'
    implementation 'com.github.javafaker:javafaker:1.0.2'

    testImplementation 'org.spockframework:spock-core:2.0-M3-groovy-3.0'
    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}

group = 'nl.topicus.overheid'
version = '0.2.0'
description = 'java-factory-bot'
sourceCompatibility = '1.8'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}
英文:

I converted a project to gradle using gradle init from maven after updating the dependencies. gradle test works as expected. However, when I run gradle build, the jar file that's generated is entirely empty.

I've attempted to tweak the source set to make something happen, but that doesn't seem to solve the problem. The directory structure matches what gradle expects from what I can tell everything is nested in src/main/groovy

The project's full code is available on Github.

In general what causes no files to be added to a build? Is there additional configuration I need to add besides whatever gradle init creates?

Gradle build file:

plugins {
    id 'java'
    id 'maven-publish'
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.5'
    implementation 'com.github.javafaker:javafaker:1.0.2'

    testImplementation 'org.spockframework:spock-core:2.0-M3-groovy-3.0'
    testCompileOnly 'org.projectlombok:lombok:1.18.12'
	testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}

group = 'nl.topicus.overheid'
version = '0.2.0'
description = 'java-factory-bot'
sourceCompatibility = '1.8'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

答案1

得分: 1

现在的情况是,该项目正在尝试构建为Java项目,并从src/main/java获取源代码,因为这是Java项目的默认设置。因此,在plugins部分中,您需要使用id 'groovy'而不是id 'java',以便它可以查找src/main/groovy,并在其中构建.java.groovy文件。

英文:

What going on now is the project is try to build as Java project and get src from src/main/java as it is default from Java project. So, you need id 'groovy' not id 'java' in plugins section to make it look into src/main/groovy and build both .java and .groovy files in there.

huangapple
  • 本文由 发表于 2020年9月11日 07:18:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63838834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定