You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派执行Gradle构建时出现「无法创建父目录」错误

Hey Simon, let's tackle these two issues one by one to get your Java app building smoothly on Raspberry Pi.


1. Fixing the PATH Environment Variable Persistence Problem

The reason your Gradle PATH only works in the local terminal is because the export command you ran only applies to the current shell session. Local and SSH sessions load different shell configuration files by default, so we need to make the PATH change permanent for all sessions of your simon user.

Here's how to fix it:

  • Open your user's bash configuration file with a text editor (nano is easy for beginners):
    nano ~/.bashrc
    
  • Scroll to the bottom of the file and add this line:
    export PATH=$PATH:/opt/gradle/gradle-6.7/bin
    
  • Save the file (press Ctrl+O, hit Enter, then Ctrl+X to exit nano)
  • Apply the changes immediately to your current session:
    source ~/.bashrc
    
  • Test it in a new SSH session: run gradle -v—it should recognize the command without needing to set PATH manually now.

2. Resolving Gradle Build Permission Errors

The core issue here is that your simon user doesn't have write permissions for the project directory /home/pi/Desktop/slotcar_project/SlotCar. Gradle needs to create the .gradle folder inside your project to store build caches, and right now it can't do that.

Let's fix this properly with one of two options:

Option 1: Grant write access to the pi group (since you added simon to this group)

If you want to keep the directory owned by pi but let simon modify it:

sudo chmod -R g+w /home/pi/Desktop/slotcar_project/SlotCar

The -R flag applies the permission change recursively to all files and subfolders in the project.

This is the simpler long-term solution since you're developing as simon:

sudo chown -R simon:simon /home/pi/Desktop/slotcar_project/SlotCar

Now simon will have full read/write/execute access to the entire project directory.

Why sudo gradle build failed

When you use sudo, it runs commands as the root user, which doesn't inherit your simon user's PATH. If you ever need to run Gradle with sudo (though you shouldn't need to for your project), you could use:

sudo -E gradle build

The -E flag preserves your user's environment variables (including PATH) when running as root. But fixing the directory permissions for simon is the correct solution here.

After applying either permission fix, navigate back to your project directory and run gradle build again—it should complete without the directory creation error.

内容的提问来源于stack exchange,提问作者SimonA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:47:52