목차
问题内容
解决方法
Java WPILIB(FRC) Gradlew 문제(Gradle은 잘 빌드되지만 gradlew는 그렇지 않음)

WPILIB(FRC) Gradlew 문제(Gradle은 잘 빌드되지만 gradlew는 그렇지 않음)

Feb 11, 2024 am 10:30 AM

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

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

위 내용은 WPILIB(FRC) Gradlew 문제(Gradle은 잘 빌드되지만 gradlew는 그렇지 않음)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)