当一个重要的导入声明被注释掉时,Netbeans报告"无需修复导入声明":
重新导入导入,项目构建并运行良好:
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$
简单构建文件:
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'
}
然而,netbeans抱怨"包javax.json不存在":
并且"创建JsonObject的类型是错误的":
问题不在于构建文件build.gradle
,也不在于源代码本身。 Netbeans的一些用法,其中IDE没有提到需要和可用的包:
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
JsonObject
就在Shadowjar
。