php小编子墨WPILIB (FRC) Gradlew 问题是指在使用Gradle构建FRC项目时,遇到gradlew命令无法正常运行的情况。虽然Gradle构建可以顺利进行,但在使用gradlew命令时却遇到了问题。这个问题可能导致项目无法正常编译和运行,给开发者带来了困扰。接下来,我们将详细解答这个问题,帮助开发者解决这一常见的难题。
我最近在 windows 笔记本电脑上安装了 wpilib 并启动了一个项目,但是当我尝试使用 gradlew
构建项目时它不起作用:
这是我的 build.gradle
:
plugins { id "java" id "edu.wpi.first.gradlerio" version "2024.1.1" } java { sourcecompatibility = javaversion.version_17 targetcompatibility = javaversion.version_17 } def robot_main_class = "frc.robot.main" // define my targets (roborio) and artifacts (deployable files) // this is added by gradlerio's backing project deployutils. deploy { targets { roborio(gettargettypeclass('roborio')) { // team number is loaded either from the .wpilib/wpilib_preferences.json // or from command line. if not found an exception will be thrown. // you can use getteamordefault(team) instead of getteamnumber if you // want to store a team number in this file. team = project.frc.getteamnumber() debug = project.frc.getdebugordefault(false) artifacts { // first part is artifact name, 2nd is artifact type // gettargettypeclass is a shortcut to get the class type using a string frcjava(getartifacttypeclass('frcjavaartifact')) { } // static files artifact frcstaticfiledeploy(getartifacttypeclass('filetreeartifact')) { files = project.filetree('src/main/deploy') directory = '/home/lvuser/deploy' } } } } } def deployartifact = deploy.targets.roborio.artifacts.frcjava // set to true to use debug for jni. wpi.java.debugjni = false // set this to true to enable desktop support. def includedesktopsupport = false // defining my dependencies. in this case, wpilib (+ friends), and vendor libraries. // also defines junit 5. dependencies { implementation wpi.java.deps.wpilib() implementation wpi.java.vendor.java() roboriodebug wpi.java.deps.wpilibjnidebug(wpi.platforms.roborio) roboriodebug wpi.java.vendor.jnidebug(wpi.platforms.roborio) roboriorelease wpi.java.deps.wpilibjnirelease(wpi.platforms.roborio) roboriorelease wpi.java.vendor.jnirelease(wpi.platforms.roborio) nativedebug wpi.java.deps.wpilibjnidebug(wpi.platforms.desktop) nativedebug wpi.java.vendor.jnidebug(wpi.platforms.desktop) simulationdebug wpi.sim.enabledebug() nativerelease wpi.java.deps.wpilibjnirelease(wpi.platforms.desktop) nativerelease wpi.java.vendor.jnirelease(wpi.platforms.desktop) simulationrelease wpi.sim.enablerelease() testimplementation 'org.junit.jupiter:junit-jupiter:5.10.1' testruntimeonly 'org.junit.platform:junit-platform-launcher' } test { usejunitplatform() systemproperty 'junit.jupiter.extensions.autodetection.enabled', 'true' } // simulation configuration (e.g. environment variables). wpi.sim.addgui().defaultenabled = true wpi.sim.adddriverstation() // setting up my jar file. in this case, adding all libraries into the main jar ('fat jar') // in order to make them all available at runtime. also adding the manifest so wpilib // knows where to look for our robot class. jar { from { configurations.runtimeclasspath.collect { it.isdirectory() ? it : ziptree(it) } } from sourcesets.main.allsource manifest edu.wpi.first.gradlerio.gradlerioplugin.javamanifest(robot_main_class) duplicatesstrategy = duplicatesstrategy.include } // configure jar and deploy tasks deployartifact.jartask = jar wpi.java.configureexecutabletasks(jar) wpi.java.configuretesttasks(test) // configure string concat to always inline compile tasks.withtype(javacompile) { options.compilerargs.add '-xdstringconcat=inline' }
现在如果我用 gradle 构建,它构建得非常好
设置.gradle:
import org.gradle.internal.os.operatingsystem pluginmanagement { repositories { mavenlocal() gradlepluginportal() string frcyear = '2024' file frchome if (operatingsystem.current().iswindows()) { string publicfolder = system.getenv('public') if (publicfolder == null) { publicfolder = "c:\\users\\public" } def homeroot = new file(publicfolder, "wpilib") frchome = new file(homeroot, frcyear) } else { def userfolder = system.getproperty("user.home") def homeroot = new file(userfolder, "wpilib") frchome = new file(homeroot, frcyear) } def frchomemaven = new file(frchome, 'maven') maven { name 'frchome' url frchomemaven } } } properties props = system.getproperties(); props.setproperty("org.gradle.internal.native.headers.unresolved.dependencies.ignore", "true");
我预计它也会使用 gradlew 构建,但事实并非如此,
这是我的 gradle-wrapper.properties
distributionbase=gradle_user_home distributionpath=permwrapper/dists distributionurl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networktimeout=10000 validatedistributionurl=true zipstorebase=gradle_user_home zipstorepath=permwrapper/dists
它没有构建它而是给了我这个:
>gradlew Exception in thread "main" java.lang.ClassNotFoundException: org.gradle.launcher.GradleMain at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) at org.gradle.wrapper.GradleWrapperMain.main(SourceFile:70)
我什至尝试重新生成包装器,gradlewrapper
另外:出于某种原因,gradlew
无论如何都不会听命令,它是唯一的构建
编辑: 我已经在 github codespaces 和我自己的 linux (arch linux) 上尝试了我的代码,但是 windows 不适合我,我已经重新安装了 wpilib 多次,不知道为什么它对我这样做。我尝试过使用 windows 虚拟机,但它的工作原理很奇怪,为什么我的计算机无法工作。
此错误的解决方案是您必须删除主目录 C:\Users\{username}\
中的 .gradle
文件夹。现在,在我的安装过程中一定发生了一些导致此错误发生的事情。现在一切都可以正确构建。
注意:在删除之前您必须重新启动计算机,因为除非重新启动,否则它不会让您删除。
Atas ialah kandungan terperinci WPILIB (FRC) Masalah Gradlew (Gradle membina dengan baik, tetapi gradlew tidak). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!