netbeans: nothing to fix in import statements. Yet, import is required. (Gradle)

浪尽此生 提交于 2019-12-11 04:45:21

问题


When a crucial import statement is commented out Netbeans reports "nothing to fix in import statement":

Putting the import back in, the project builds and runs fine:

thufir@dur:~/NetBeansProjects/HelloJsonGradle$ 
thufir@dur:~/NetBeansProjects/HelloJsonGradle$ gradle clean shadowJar

> Task :shadowJar
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.


BUILD SUCCESSFUL in 1s
4 actionable tasks: 4 executed
thufir@dur:~/NetBeansProjects/HelloJsonGradle$ 
thufir@dur:~/NetBeansProjects/HelloJsonGradle$ java -jar build/libs/JsonShadowJar.jar 
Oct 22, 2017 3:41:58 AM net.bounceme.dur.json_gradle.Main props
INFO: {foo=bar}
Oct 22, 2017 3:41:58 AM net.bounceme.dur.json_gradle.JsonOperations createJsonObject
INFO: creating..
Oct 22, 2017 3:41:58 AM net.bounceme.dur.json_gradle.Main json
INFO: {"name":"Falco","age":3,"biteable":false}
thufir@dur:~/NetBeansProjects/HelloJsonGradle$ 

simple build file:

plugins {
    id 'com.gradle.build-scan' version '1.8' 
    id 'java'
    id 'application'
    id 'com.github.johnrengelman.shadow' version '2.0.1'
}

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
    //publishAlways()
}

sourceCompatibility = 1.9
targetCompatibility = 1.9

mainClassName = 'net.bounceme.dur.json_gradle.Main'

shadowJar {
    baseName = 'JsonShadowJar'
    classifier = null
    version = null
}

repositories {
    jcenter()
}

configurations {
    provided
}

dependencies {
    compile group: 'javax.json', name: 'javax.json-api', version: '1.1'
    compile group: 'org.glassfish', name: 'javax.json', version: '1.0.4'
} 

yet, netbeans complains that the "package javax.json does not exist":

and that "the type of create JsonObject is erroneous":

The problem isn't with the build file, build.gradle, nor with the source code itself. Some sort of usage with Netbeans where the IDE isn't picking up that the package is needed and available:

thufir@dur:~/NetBeansProjects/HelloJsonGradle$ 
thufir@dur:~/NetBeansProjects/HelloJsonGradle$ jar -tf build/libs/JsonShadowJar.jar 
META-INF/
META-INF/MANIFEST.MF
net/
net/bounceme/
net/bounceme/dur/
net/bounceme/dur/json_gradle/
net/bounceme/dur/json_gradle/Main.class
net/bounceme/dur/json_gradle/PropertiesUtils.class
net/bounceme/dur/json_gradle/JsonOperations.class
person.json
properties.properties
connection.properties
META-INF/maven/
META-INF/maven/javax.json/
META-INF/maven/javax.json/javax.json-api/
META-INF/maven/javax.json/javax.json-api/pom.properties
META-INF/maven/javax.json/javax.json-api/pom.xml
javax/
javax/json/
javax/json/Json.class
javax/json/JsonArray.class
javax/json/JsonArrayBuilder.class
javax/json/JsonBuilderFactory.class
javax/json/JsonException.class
javax/json/JsonMergePatch.class
javax/json/JsonNumber.class
javax/json/JsonObject.class

The JsonObject is right there in the Shadowjar.

来源:https://stackoverflow.com/questions/46873255/netbeans-nothing-to-fix-in-import-statements-yet-import-is-required-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!