简体   繁体   English

Gradle不知道Java语法错误吗?

[英]Gradle not aware of Java syntax errors?

When I run my "build" Gradle task it is downloading all my dependencies as expected, however it does not seem to pick up on the fact that I have a Java Syntax error. 当我运行我的"build" Gradle任务时,它正在按预期方式下载我的所有依赖项,但是似乎并没有发现我有Java语法错误这一事实

I have purposely created a syntax error with a missing ; 故意创建了一个缺少语法错误; to check this. 检查一下。

Why is this happening and how can I solve this? 为什么会发生这种情况,我该如何解决?

Java class: Java类:

package client;

import org.hibernate.Session;

import util.HibernateUtil;
import entity.Message;


public class HelloWorldClient {
    public static void main(String[] args) {

                Session session = HibernateUtil.getSessionFactory().openSession();
                session.beginTransaction();

                Message message = new Message( "Hello World with Hibernate & JPA Annotations" ) //note no ;

                session.save(message);

                session.getTransaction().commit();
                session.close();

    }
}

Build.gradle: 的build.gradle:

group 'test'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

mainClassName = "src.client.HelloWorldClient"

repositories {
    mavenCentral()
}

dependencies {
    compile 'mysql:mysql-connector-java:5.1.38'
    compile 'antlr:antlr:2.7.7'
    compile 'dom4j:dom4j:1.6.1'
    compile 'org.hibernate.common:hibernate-commons-annotations:4.0.4.Final'
    compile 'org.hibernate:hibernate-core:4.3.5.Final'
    compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
    compile 'org.jboss:jandex:1.1.0.Final'
    compile 'org.javassist:javassist:3.18.1-GA'
    compile 'org.jboss.logging:jboss-logging:3.1.3.GA'
    compile 'org.jboss.logging:jboss-logging-annotations:1.2.0.Beta1'
    compile 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final'
}

Congifuration: Congifuration:

在此处输入图片说明

Project Structure: 项目结构:

在此处输入图片说明

Output after dependencies downloaded: 下载依赖项后的输出:

All projects evaluated.
Selected primary task 'build' from project :
Tasks to be executed: [task ':compileJava', task ':processResources', task ':classes', task ':jar', task ':startScripts', task ':distTar', task ':distZip', task ':assemble', task ':compileTestJava', task ':processTestResources', task ':testClasses', task ':test', task ':check', task ':build']
:compileJava (Thread[Daemon worker Thread 4,5,main]) started.
:compileJava
Skipping task ':compileJava' as it has no source files.
:compileJava UP-TO-DATE
:compileJava (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.
:processResources (Thread[Daemon worker Thread 4,5,main]) started.
:processResources
Skipping task ':processResources' as it has no source files.
:processResources UP-TO-DATE
:processResources (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.002 secs.
:classes (Thread[Daemon worker Thread 4,5,main]) started.
:classes
Skipping task ':classes' as it has no actions.
:classes UP-TO-DATE
:classes (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.0 secs.
:jar (Thread[Daemon worker Thread 4,5,main]) started.
:jar
Skipping task ':jar' as it is up-to-date (took 0.004 secs).
:jar UP-TO-DATE
:jar (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.006 secs.
:startScripts (Thread[Daemon worker Thread 4,5,main]) started.
:startScripts
Skipping task ':startScripts' as it is up-to-date (took 0.065 secs).
:startScripts UP-TO-DATE
:startScripts (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.067 secs.
:distTar (Thread[Daemon worker Thread 4,5,main]) started.
:distTar
Skipping task ':distTar' as it is up-to-date (took 0.008 secs).
:distTar UP-TO-DATE
:distTar (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.014 secs.
:distZip (Thread[Daemon worker Thread 4,5,main]) started.
:distZip
Skipping task ':distZip' as it is up-to-date (took 0.009 secs).
:distZip UP-TO-DATE
:distZip (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.016 secs.
:assemble (Thread[Daemon worker Thread 4,5,main]) started.
:assemble
Skipping task ':assemble' as it has no actions.
:assemble UP-TO-DATE
:assemble (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.
:compileTestJava (Thread[Daemon worker Thread 4,5,main]) started.
:compileTestJava
Skipping task ':compileTestJava' as it has no source files.
:compileTestJava UP-TO-DATE
:compileTestJava (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.002 secs.
:processTestResources (Thread[Daemon worker Thread 4,5,main]) started.
:processTestResources
Skipping task ':processTestResources' as it has no source files.
:processTestResources UP-TO-DATE
:processTestResources (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.002 secs.
:testClasses (Thread[Daemon worker Thread 4,5,main]) started.
:testClasses
Skipping task ':testClasses' as it has no actions.
:testClasses UP-TO-DATE
:testClasses (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.
:test (Thread[Daemon worker Thread 4,5,main]) started.
:test
Skipping task ':test' as it has no source files.
:test UP-TO-DATE
:test (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.
:check (Thread[Daemon worker Thread 4,5,main]) started.
:check
Skipping task ':check' as it has no actions.
:check UP-TO-DATE
:check (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.
:build (Thread[Daemon worker Thread 4,5,main]) started.
:build
Skipping task ':build' as it has no actions.
:build UP-TO-DATE
:build (Thread[Daemon worker Thread 4,5,main]) completed. Took 0.001 secs.

BUILD SUCCESSFUL

Total time: 0.316 secs
Stopped 0 compiler daemon(s).
22:06:01: External task execution finished 'build --info'.

New Project Structure: 新项目结构:

在此处输入图片说明

You don't have any source files under src/main/java . src/main/java下没有任何源文件。 Move the client, domain, entity packages under there and you'll get your compile error :) 将客户端,域,实体包移到该目录下,您将得到编译错误:)

Skipping task ':compileJava' as it has no source files. 正在跳过任务':compileJava',因为它没有源文件。

Move your sources to src/main/java or adjust your build file. 将源移至src/main/java或调整构建文件。

See 23.4 https://docs.gradle.org/current/userguide/java_plugin.html 参见23.4 https://docs.gradle.org/current/userguide/java_plugin.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM