0

0

WPILIB (FRC) Gradlew 问题(Gradle 构建正常,但 gradlew 不行)

王林

王林

发布时间:2024-02-11 10:30:09

|

1263人浏览过

|

来源于stackoverflow

转载

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

Artbreeder
Artbreeder

创建令人惊叹的插画和艺术

下载
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 文件夹。现在,在我的安装过程中一定发生了一些导致此错误发生的事情。现在一切都可以正确构建。

注意:在删除之前您必须重新启动计算机,因为除非重新启动,否则它不会让您删除。

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php文件怎么打开
php文件怎么打开

打开php文件步骤:1、选择文本编辑器;2、在选择的文本编辑器中,创建一个新的文件,并将其保存为.php文件;3、在创建的PHP文件中,编写PHP代码;4、要在本地计算机上运行PHP文件,需要设置一个服务器环境;5、安装服务器环境后,需要将PHP文件放入服务器目录中;6、一旦将PHP文件放入服务器目录中,就可以通过浏览器来运行它。

2522

2023.09.01

php怎么取出数组的前几个元素
php怎么取出数组的前几个元素

取出php数组的前几个元素的方法有使用array_slice()函数、使用array_splice()函数、使用循环遍历、使用array_slice()函数和array_values()函数等。本专题为大家提供php数组相关的文章、下载、课程内容,供大家免费下载体验。

1599

2023.10.11

php反序列化失败怎么办
php反序列化失败怎么办

php反序列化失败的解决办法检查序列化数据。检查类定义、检查错误日志、更新PHP版本和应用安全措施等。本专题为大家提供php反序列化相关的文章、下载、课程内容,供大家免费下载体验。

1493

2023.10.11

php怎么连接mssql数据库
php怎么连接mssql数据库

连接方法:1、通过mssql_系列函数;2、通过sqlsrv_系列函数;3、通过odbc方式连接;4、通过PDO方式;5、通过COM方式连接。想了解php怎么连接mssql数据库的详细内容,可以访问下面的文章。

952

2023.10.23

php连接mssql数据库的方法
php连接mssql数据库的方法

php连接mssql数据库的方法有使用PHP的MSSQL扩展、使用PDO等。想了解更多php连接mssql数据库相关内容,可以阅读本专题下面的文章。

1416

2023.10.23

html怎么上传
html怎么上传

html通过使用HTML表单、JavaScript和PHP上传。更多关于html的问题详细请看本专题下面的文章。php中文网欢迎大家前来学习。

1234

2023.11.03

PHP出现乱码怎么解决
PHP出现乱码怎么解决

PHP出现乱码可以通过修改PHP文件头部的字符编码设置、检查PHP文件的编码格式、检查数据库连接设置和检查HTML页面的字符编码设置来解决。更多关于php乱码的问题详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1445

2023.11.09

php文件怎么在手机上打开
php文件怎么在手机上打开

php文件在手机上打开需要在手机上搭建一个能够运行php的服务器环境,并将php文件上传到服务器上。再在手机上的浏览器中输入服务器的IP地址或域名,加上php文件的路径,即可打开php文件并查看其内容。更多关于php相关问题,详情请看本专题下面的文章。php中文网欢迎大家前来学习。

1306

2023.11.13

Java 桌面应用开发(JavaFX 实战)
Java 桌面应用开发(JavaFX 实战)

本专题系统讲解 Java 在桌面应用开发领域的实战应用,重点围绕 JavaFX 框架,涵盖界面布局、控件使用、事件处理、FXML、样式美化(CSS)、多线程与UI响应优化,以及桌面应用的打包与发布。通过完整示例项目,帮助学习者掌握 使用 Java 构建现代化、跨平台桌面应用程序的核心能力。

36

2026.01.14

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号