跳到正文
Skillpedia
API 与服务器(后端)22k · #10356

build-native-image-gradle

它能做什么

这项技能帮助 Java 开发人员把 Gradle 项目变成启动迅速的原生程序。适合希望获得更轻、更快 Java 应用的团队。

适用场景

  • ✓你想用 Gradle 把 Java 应用构建为 GraalVM 原生镜像的时候。
  • ✓原生镜像构建因类初始化、链接或内存错误而失败的时候。
  • ✓你需要为 Gradle 项目设置原生测试,或修复缺失的反射元数据的时候。

技能链接

https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-gradle/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-gradle/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把我的 Gradle Java 应用设置为构建 GraalVM 原生镜像,并运行原生测试。”

每周 5 个新技能,1 分钟读完。

工作原理

它会把 GraalVM Native Build Tools 插件添加到你的构建文件中,然后运行原生编译、运行和测试任务。它使用设为 JAVA_HOME 的 GraalVM JDK,并指向已知构建问题的指南。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Gradle Native Image Build

Prerequisites

  • Set JAVA_HOME to a GraalVM JDK installation so Gradle Native Build Tools can find native-image.
  • Do not require GRAALVM_HOME in the normal case. Only mention it if the user already relies on it or their environment needs an explicit override.
  • Apply the application, java-library, or java plugin along with org.graalvm.buildtools.native.

Plugin Setup

Groovy DSL:

plugins {
    id 'application'
    id 'org.graalvm.buildtools.native' version '0.11.1'
}

Kotlin DSL:

plugins {
    application
    id("org.graalvm.buildtools.native") version "0.11.1"
}

Build and Run

./gradlew nativeCompile   # Build to build/native/nativeCompile/
./gradlew nativeRun       # Build and run the native executable
./gradlew nativeTest      # Build and run JUnit tests as a native image

Build or Runtime Failures

If the build fails with class initialization, linking errors, memory issues, or the binary behaves incorrectly at runtime, see references/native-image-build-gradle-options.md.

Native Testing

If nativeTest fails or you need to configure native JUnit tests or custom test suites, see references/testing.md.

Missing Reachability Metadata

If a build or runtime error reports missing reflection, resource, serialization, or JNI registrations, see references/reachability-metadata.md.

Reference Files

Topic File
DSL options and build arguments references/native-image-build-gradle-options.md
Missing reachability metadata references/reachability-metadata.md
Native testing references/testing.md
常见问题

需要安装什么 Java 版本?

需要 GraalVM JDK,并将其设为 JAVA_HOME,以便找到 native-image 工具。

它也支持 Maven 吗?

这项技能负责 Gradle,Maven 有单独的技能。

它能帮忙处理缺失的元数据吗?

能。它涵盖缺失的反射和资源元数据错误。

详情

作者的原始描述

Build GraalVM native images using Gradle Native Build Tools. Use this skill to build Java applications with Gradle, configure native-image build.gradle settings, or resolve build or runtime issues.

repo: oracle/graal

热度

GitHub 星标
22k
排名
#10356
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能