如何在NetBeans中导入Jackson Core的JacksonFactory?
NetBeans下Gradle项目无法自动补全导入语句
项目基于Google Sheets API Java快速启动示例,在NetBeans环境中无法正常构建,其他环境无此问题。我希望NetBeans能自动添加必要的导入语句,目前缺失JsonFactory相关的导入。
代码示例
package sheets; public class App { public String getGreeting() { return "Hello World!"; } private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart"; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static final String TOKENS_DIRECTORY_PATH = "tokens"; private static final List<String> SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS, SheetsScopes.DRIVE, SheetsScopes.DRIVE_FILE); private static final String CREDENTIALS_FILE_PATH = "/credentials.json"; public static void main(String[] args) { System.out.println(new App().getGreeting()); } }
当前问题
代码中多个类(如JsonFactory、JacksonFactory、List、Arrays、SheetsScopes)无法被解析,截图如下:
系统已能识别部分依赖,说明依赖配置本身应该有效,但NetBeans并未自动补全全部必要的导入语句。
Gradle依赖配置
/* * This file was generated by the Gradle 'init' task. * * This generated file contains a sample Java application project to get you started. * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle * User Manual available at https://docs.gradle.org/8.1.1/userguide/building_java_projects.html * This project uses @Incubating APIs which are subject to change. */ plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' } repositories { // Use Maven Central for resolving dependencies. mavenCentral() } dependencies { // This dependency is used by the application. implementation 'com.google.guava:guava:31.1-jre' // https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client // implementation group: 'com.google.oauth-client', name: 'google-oauth-client', version: '1.34.1' // https://mvnrepository.com/artifact/com.google.api-client/google-api-client implementation group: 'com.google.api-client', name: 'google-api-client', version: '2.2.0' // https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-jetty implementation group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.34.1' // https://mvnrepository.com/artifact/com.google.apis/google-api-services-sheets implementation group: 'com.google.apis', name: 'google-api-services-sheets', version: 'v4-rev612-1.25.0' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.2' // https://mvnrepository.com/artifact/com.google.api-client/google-api-client-jackson2 implementation group: 'com.google.api-client', name: 'google-api-client-jackson2', version: '1.20.0' } testing { suites { // Configure the built-in test suite test { // Use TestNG test framework useTestNG('7.5') } } } // Apply a specific Java toolchain to ease working on different environments. java { toolchain { languageVersion = JavaLanguageVersion.of(20) } } application { // Define the main class for the application. mainClass = 'sheets.App' }
补充说明
此问题仅出现在NetBeans环境中,后续我会尝试手动添加固定导入语句后更新问题。
内容的提问来源于stack exchange,提问作者Nicholas Saunders
相关产品推荐
相关产品推荐

