如何授予生成文件夹权限,以便gradle在执行compilejava任务时不会失败?

holgip5t  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(491)

所以,我有一个springboot的gradle项目,上周它运行得很好(我发誓!)但本周,当我再次尝试构建它时,它给了我一个丑陋的错误,经过几个小时的跟踪和研究,我得出结论,这与权限有关,因为每次我尝试构建项目时,构建文件夹都会被删除。
要构建项目并生成war文件,我使用命令./gradlew bootwar
一开始,我得到一个错误:

./gradlew: line 39: cd: "./: No such file or directory

<-------------> 0% EXECUTING [97ms]> :compileJava > Resolve dependencies of :compileClasspath > Resolve dependenci<-------------> 0% EXECUTING [197ms]> :compileJava > Resolve dependencies of :compileClasspath> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':compileJava'.
> java.io.FileNotFoundException: C:\Development\mainapp\build\tmp\compileJava\source-classes-mapping.txt (Access is denied)

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
1 actionable task: 1 executed

<-------------> 0% WAITING> :compileJava > Resolve dependencies of :compileClasspath> IDLE

如您所见,名为source-classes-mapping.txt的文件似乎有错误,因此我用更改了权限
chmod 775 source-classes-mapping.txt文件
这是因为在我更改权限之前,它甚至不允许我打开记事本上的文件。因此,在此之后,我再次尝试使用gradlew bootwar构建,但现在出现以下错误:

./gradlew: line 39: cd: "./: No such file or directory

> Connecting to Daemon<-------------> 0% EXECUTING [84ms]> :compileJava > Resolve dependencies of :compileClasspath > Resolve dependenci<-------------> 0% EXECUTING [186ms]<-------------> 0% EXECUTING [286ms]> :compileJava<-------------> 0% EXECUTING [386ms]<-------------> 0% EXECUTING [484ms]
> Task :compileJava FAILED
C:\Development\mainapp\src\main\java\com\mycompany\mainapp\config\ConfigOptions.java:8: error: error while writing ConfigOptions: C:\Development\mainapp\build\classes\java\main\com\mycompany\mainapp\config\ConfigOptions.class
public class ConfigOptions {
       ^
1 error

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for 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.

获取更多帮助https://help.gradle.org
此版本中使用了不推荐的gradle功能,使其与gradle 7.0不兼容。使用“--warning mode all”来显示各个弃用警告。看到了吗https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:命令行警告
生成在1s中失败1个可操作任务:1个已执行
<

vlurs2pr

vlurs2pr1#

->0%等待>:compilejava
看起来它无法将类文件写入正确的文件夹,我使用ls-l和这些文件夹进行了检查,从/com/开始对所有者没有权限,在我第二次构建它之后,源类Map文件的权限被重置。
当然,我也尝试使用chmod命令的-r选项为整个build文件夹、java文件夹(build文件夹中的文件夹)甚至/com/文件夹下的每个子文件夹授予权限,但它不能在这些文件夹上写入
我想这是因为每次我构建项目时,它都会删除这些文件夹,当它再次创建它们时,它们就不再有权限了。我发现这是因为有一次,我试图建立和我的终端内的com文件夹,这一次它失败了,因为它不能删除这些文件夹。
所以问题是,就像标题所说的,如何设置构建文件夹的权限,以便每次尝试构建项目时都不会失败?
更多信息:我使用的是windows10,但是我使用的是cygwin终端,所以我有一个类似linux的环境
我不知道是否需要,但这是我的build.gradle文件

buildScript {
   repositories {
      maven {
         url "http://some.corporation.repository/Repository"
      }
   }
   dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.+")
    }
}

plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.example'

apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'

bootWar {
    baseName='mainapp-jar'
    mainClassName='org.springframework.boot.loader.WarLauncher'
    manifest {
        attributes 'Main-Class': 'org.springframework.boot.loader.WarLauncher'
        attributes 'Start-Class': 'com.mycompany.mainapp.MainappApplication'
    }
}
sourceCompatibility = '1.11'

repositories {
      url "http://some.corporation.repository/Repository"
 }

war {enabled=true}
jar {enabled=false}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-actuator'

    compile group: "javax.servlet", name: "jstl", version: "$jstlVersion"
    compile group: "org.apache.tomcat.embed", name: "tomcat-embed-jasper"
}

提前谢谢!

相关问题