当前位置: 首页 > 知识库问答 >
问题:

gradle构建失败,任务“:compilejava”执行失败

雍俊远
2023-03-14

我在一个Java桌面应用程序中使用gradle。

IDE是NetBeans&我想从我的Java类生成一些自动化的JSON。

我实现了3个类(仅POJOs)&试图通过Gradle导入'com.github.reinert',名称:'jjschema',版本:'1.11'。

jjschema将打印java对象的JSON等价物。

然而,gradle并没有解析这些类&也没有下载依赖项。

这是我的gradle档案:

  apply plugin: 'java'

    sourceCompatibility = '1.8'
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

    // NetBeans will automatically add "run" and "debug" tasks relying on the
    // "mainClass" property. You may however define the property prior executing
    // tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
    //
    // Note however, that you may define your own "run" and "debug" task if you
    // prefer. In this case NetBeans will not add these tasks but you may rely on
    // your own implementation.
    if (!hasProperty('mainClass')) {
        ext.mainClass = ''
    }

    repositories {
        mavenCentral()
        // You may define additional repositories, or even remove "mavenCentral()".
        // Read more about repositories here:
        //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
    }

    dependencies {
        // TODO: Add dependencies here ...
        // You can read more about how to add dependency here:
        //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies

//I also tried compile group: 'com.github.reinert', name: 'jjschema', version: '1.11'

       implementation group: 'com.github.reinert', name: 'jjschema', version: '1.11'
    }

以下是我的POJO,按移动设备顺序排列:

package x_mqtt_message;

import java.util.ArrayList;
import java.util.List;

public class MobileDevice {
    //most likely a phone number tied to the device if available or other id
    private String softwareId; 
    //device's hardwareId, is import if the user changes the phone or swaps SIM cards, we can still identify the hardware for tracking/diagnostics/debugging 
    private String hardwareId; 
    //services running on the device 
    private List<xService> services = new ArrayList<xService>();

    public String getSoftwareId() {
        return softwareId;
    }

    public void setSoftwareId(String softwareId) {
        this.softwareId = softwareId;
    }

    public String getHardwareId() {
        return hardwareId;
    }

    public void setHardwareId(String hardwareId) {
        this.hardwareId = hardwareId;
    }

    public List<xService> getServices() {
        return services;
    }

    public void setServices(List<xService> services) {
        this.services = services;
    }
package x_mqtt_message;

import com.github.reinert.jjschema.Attributes;


@Attributes(title="xSensor", description="An external sensor such as ECG,temp,Accelerometer,Pulse-oximete,Barometric Pressure,etc...")
public class xSensor {
    //unique id of the sensor 
    @Attributes(required=true, description="unique id of the sensor")
    private String id;  
    //type such as ECG,body_temperature,accelerometer,pulse-oximeter,barometric_pressure
    @Attributes(required=true, description="type such as ECG,body_temperature,accelerometer,pulse-oximeter,barometric_pressure")
    private String type;
    @Attributes(minItems=0,uniqueItems=false)
    private Object [] data; 

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Object[] getData() {
        return data;
    }

    public void setData(Object[] data) {
        this.data = data;
    }

}
package x_mqtt_message;

import com.github.reinert.jjschema.Attributes;
import java.util.HashSet;

@Attributes(title="xService", description="A background process that send & receives data via several protocol")
public class xService {

    //service examples: mqtt_service, gps_service, compass_service, bluetooth_service, etc...
    @Attributes(required=true, description="mqtt_service, gps_service, compass_service, bluetooth_service, etc...")
    private String serviceName; 
    //is the service 100% up & running yes=true no=false 
    @Attributes(required=true, description="is the service 100% up & running yes=true no=false")
    private Boolean serviceStatus= false; 

    @Attributes(minItems=0,uniqueItems=true)
    private HashSet<xSensor> listOfSensors = new  HashSet<xSensor>(); 

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }


}
package x_mqtt_message;


public class x_mqtt_message {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // These packages are NOT being found!!!!

JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory();
schemaFactory.setAutoPutDollarSchema(true);
JsonNode productSchema = schemaFactory.createSchema(MobileDevice.class);
System.out.println(productSchema);
    }

}

:Clean C:\x\documents\netbeansprojects\ngfrmessage\src\main\java\ngfr_mqtt_message\ngfr_mqtt_message.java:17:错误:找不到符号JsonSchemaFactory schemaFactory=new jsonschemaav4Factory();^symbol:类JsonSchemaFactory位置:类Ngfr_mqtt_message C:\x\documents\netbeansprojects\ngfrmessage\src\main\java\Ngfr_mqtt_message\Ngfr_mqtt_message\Ngfr_mqtt_message.java:17:错误:找不到符号JsonSchemaFactory schemaFactory=new jsonschemaav4Factory();^symbol:类JSONSchemaV4工厂位置:类Ngfr_mqtt_message C:\X\documents\netbeansProjects\ngFRMessage\src\main\java\Ngfr_mqtt_message\Ngfr_mqtt_message\Ngfr_mqtt_message.java:19:错误:找不到符号JsonNode productSchema=schemafactory.createSchema(mobiledevice.class);^symbol:类JsonNode位置:类Ngfr_mqtt_message 3错误:compilejava失败

失败:生成失败,出现异常。

>

  • 错误:任务':compilejava'执行失败。

    编译失败;有关详细信息,请参阅编译器错误输出。

  • 共有1个答案

    谷弘致
    2023-03-14

    但是在x_mqtt_message中没有导入JSONSchemafactory。因此编译器找不到这些类。

     类似资料: