Java Can';t在docker内部构建gradle应用程序

Java Can';t在docker内部构建gradle应用程序,java,spring,docker,gradle,dockerfile,Java,Spring,Docker,Gradle,Dockerfile,我正在尝试从docker容器中使用gradle构建一个应用程序。 这是我的Dockerfile: FROM openjdk:8-jdk #install git RUN apt-get install -y git RUN git clone https://github.com/SFRJ/yurl.git #install gradle RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip RUN u

我正在尝试从docker容器中使用gradle构建一个应用程序。 这是我的Dockerfile:

FROM openjdk:8-jdk
#install git
RUN apt-get install -y git
RUN git clone https://github.com/SFRJ/yurl.git
#install gradle
RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip
RUN unzip gradle-6.5-bin.zip
ENV GRADLE_HOME /gradle-6.5
ENV PATH $PATH:/gradle-6.5/bin
#compile and run app
RUN cd yurl
RUN gradle clean build --rerun-tasks --no-build-cache
ENTRYPOINT ["java", "-jar", "/yurlapp.jar"]
在执行build命令之前,一切都很顺利。它抛出以下内容:

Step 9/10 : RUN gradle clean build --rerun-tasks --no-build-cache
 ---> Running in a25d344c3571

Welcome to Gradle 6.5!

Here are the highlights of this release:
 - Experimental file-system watching
 - Improved version ordering
 - New samples

For more details see https://docs.gradle.org/6.5/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project ''.
> The project name must not be empty. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/6.5/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details).

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
ERROR: Service 'yurlapp' failed to build: The command '/bin/sh -c gradle clean build --rerun-tasks --no-build-cache' returned a non-zero code: 1
我只是不明白那是什么。当我在docker外部运行相同的命令,但在docker内部失败时,应用程序构建得非常好。这不是一个多模块项目,不知道为什么它会抱怨rootProject

我可以确认我有一个settings.gradle文件,里面有这个

rootProject.name = 'yurl'
这也是我的身材,格雷德尔

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath "org.postgresql:postgresql:42.2.11"
    }
}

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'org.flywaydb.flyway' version '6.3.0'
    id 'nu.studer.jooq' version '4.1'
}

group 'com.javing.yurl'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    annotationProcessor 'org.projectlombok:lombok:1.18.8'

    implementation 'org.jooq:jooq'
    implementation 'org.jooq:jooq-codegen'
    jooqRuntime 'org.postgresql:postgresql:42.2.11'
    compile 'org.postgresql:postgresql:42.2.11'
    implementation 'org.projectlombok:lombok:1.18.8'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-jooq'
    implementation 'io.vavr:vavr:0.10.2'
    implementation 'com.konghq:unirest-java:3.7.00'

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
    testCompile group: 'org.assertj', name: 'assertj-core', version: '3.15.0'

}

jooq {
    sample(sourceSets.main) {
        jdbc {
            driver = 'org.postgresql.Driver'
            url = 'jdbc:postgresql://yurldb:5432/yurldb'
            user = 'postgres'
            password = 'somepassword'
        }
        generator {
            database() {
                name = 'org.jooq.meta.postgres.PostgresDatabase'
                inputSchema = 'public'
                includes = '.*'
            }
            target {
                packageName = 'com.javing.yurl'
                directory = 'build/generated/java'
            }
        }
    }
}

tasks.generateSampleJooqSchemaSource.with {
    def out = new ByteArrayOutputStream()
    javaExecSpec = { JavaExecSpec s ->
        s.standardOutput = out
        s.errorOutput = out
        s.ignoreExitValue = true
        s.jvmArgs '-Xmx512M'
    }
    execResultHandler = { ExecResult r ->
        if (r.exitValue != 0) {
            throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
        }
    }
}

flyway {
    url = 'jdbc:postgresql://localhost:5432/yurldb'
    user = 'postgres'
    password = 'somepassword'
    schemas = ['public']
    locations = ["filesystem:$project.projectDir/src/main/resources/db/migration"]
}
我不知道如何解决这个问题,我尝试了很多方法,但都没有效果。我需要使用gradle从docker内部构建此应用程序。我知道gradle安装正确,因为如果我在docker文件中添加version命令(RUN gradle-v),我可以在docker运行时看到打印的内容:

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_252 (Oracle Corporation 25.252-b09)
OS:           Linux 4.18.0-25-generic amd64
因此,我的渐变和渐变的配置似乎还可以。另外,我知道git的安装和项目的克隆都很好,因为如果我在Dockerfile中添加一个RUN ls-s,它将正确打印项目的所有内容


build.gradle或settings.gradle文件中可能有问题。你知道会是什么吗?

你能试试下面的
Dockerfile
,因为它有点变化

FROM openjdk:8-jdk
#install git
RUN apt-get install -y git
RUN git clone https://github.com/SFRJ/yurl.git
#install gradle
RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip
RUN unzip gradle-6.5-bin.zip
ENV GRADLE_HOME /gradle-6.5
ENV PATH $PATH:/gradle-6.5/bin
#compile and run app
WORKDIR yurl
RUN gradle clean build --rerun-tasks --no-build-cache
ENTRYPOINT ["java", "-jar", "/yurlapp.jar"]

问题是,您提到了一个stage
RUN cd yurl
,其中您正在更改一个目录,该目录仅对该特定stage有效,对其余stage无效。如果您还想将该特定目录用于其他阶段。使用
WORKDIR
运行我上面所做的操作


注意:-如果您只想在1个阶段中使用该目录,那么不要使用
WORKDIR
而是在1个阶段中使用
运行cd DIR&&ls-lart
类似的命令。

是的,就是这样。ThanksAn解释错在哪里将受到鼓励,不仅仅是解决方案。我们也添加了解释