简体   繁体   中英

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.

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:

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:

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:

在此处输入图片说明

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 . Move the client, domain, entity packages under there and you'll get your compile error :)

Skipping task ':compileJava' as it has no source files.

Move your sources to src/main/java or adjust your build file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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