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

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

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

  1. ./gradlew: line 39: cd: "./: No such file or directory
  2. <-------------> 0% EXECUTING [97ms]> :compileJava > Resolve dependencies of :compileClasspath > Resolve dependenci<-------------> 0% EXECUTING [197ms]> :compileJava > Resolve dependencies of :compileClasspath> Task :compileJava FAILED
  3. FAILURE: Build failed with an exception.
  4. * What went wrong:
  5. Execution failed for task ':compileJava'.
  6. > java.io.FileNotFoundException: C:\Development\mainapp\build\tmp\compileJava\source-classes-mapping.txt (Access is denied)
  7. * Try:
  8. 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.
  9. * Get more help at https://help.gradle.org
  10. Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
  11. Use '--warning-mode all' to show the individual deprecation warnings.
  12. See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings
  13. BUILD FAILED in 1s
  14. 1 actionable task: 1 executed
  15. <-------------> 0% WAITING> :compileJava > Resolve dependencies of :compileClasspath> IDLE

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

  1. ./gradlew: line 39: cd: "./: No such file or directory
  2. > 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]
  3. > Task :compileJava FAILED
  4. 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
  5. public class ConfigOptions {
  6. ^
  7. 1 error
  8. FAILURE: Build failed with an exception.
  9. * What went wrong:
  10. Execution failed for task ':compileJava'.
  11. > Compilation failed; see the compiler error output for details.
  12. * Try:
  13. 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文件

  1. buildScript {
  2. repositories {
  3. maven {
  4. url "http://some.corporation.repository/Repository"
  5. }
  6. }
  7. dependencies {
  8. classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.+")
  9. }
  10. }
  11. plugins {
  12. id 'org.springframework.boot' version '2.3.5.RELEASE'
  13. id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  14. id 'java'
  15. }
  16. group = 'com.example'
  17. apply plugin: 'war'
  18. apply plugin: 'org.springframework.boot'
  19. apply plugin: 'io.spring.dependency-management'
  20. apply plugin: 'java'
  21. bootWar {
  22. baseName='mainapp-jar'
  23. mainClassName='org.springframework.boot.loader.WarLauncher'
  24. manifest {
  25. attributes 'Main-Class': 'org.springframework.boot.loader.WarLauncher'
  26. attributes 'Start-Class': 'com.mycompany.mainapp.MainappApplication'
  27. }
  28. }
  29. sourceCompatibility = '1.11'
  30. repositories {
  31. url "http://some.corporation.repository/Repository"
  32. }
  33. war {enabled=true}
  34. jar {enabled=false}
  35. dependencies {
  36. compile 'org.springframework.boot:spring-boot-starter-web'
  37. compile 'org.springframework.boot:spring-boot-starter-actuator'
  38. compile group: "javax.servlet", name: "jstl", version: "$jstlVersion"
  39. compile group: "org.apache.tomcat.embed", name: "tomcat-embed-jasper"
  40. }

提前谢谢!

展开查看全部

相关问题