Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Java compile ignoring non-java source files

I have some .properties files along with .java files in the java project. When Gradle compiles it seems to be only taking .class file and ignoring the .properties files & .csv files while making the jar.

Can anyone let us know how to get the .properties files, .csv files also gets compiled into the classes folder?

For example, if my project has the following files,

"src/main/java/com/spcapitaliq/test/Test.java"
"src/main/java/com/spcapitaliq/test/Test.properties"
"src/main/java/com/spcapitaliq/test/Test.csv"

I am seeing only the Test.class in the classes folder not the Test.properties & Test.csv files. Can you let me know how to include the .properties files & .csv files during the gradle compilation process. In eclipse, its bringing both but gradle compile is ignoring that.

The following is my SourceSet entry in "gradle.build" file,

sourceSets
    {
        main
        {
            java
            {
                srcDir 'src/main/java’
            }
            resources
            {
                srcDir 'src/main/resources'compileClasspath = configurations.runtime + fileTree(dir:"$project.HOME_DIR/$project.SERVICE_NAME/lib", includes: ['*.jar'])
            }
    }
like image 517
Amjath Sharief Avatar asked Aug 13 '14 10:08

Amjath Sharief


People also ask

What is compileJava in Gradle?

compileJava — JavaCompile. Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies. Compiles production Java source files using the JDK compiler. processResources — ProcessResources.

What is runtimeClasspath in Gradle?

main. runtimeClasspath' contains the compiled classes of the source set, and task autowiring automatically adds the necessary task dependencies. Maybe you want 'sourceSets. main. compileClasspath'.

What is sourceCompatibility in Gradle?

According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."

What is Gradle Annotationprocessor?

An annotation processor is a class which extends AbstractProcessor (in the package javax. annotation. processing ) providing the functionality needed to generate whatever it needs to generate, such as classes in the case of mapstruct.


1 Answers

Just add the required files to the default processResources task:

processResources {
  from ('src/main/java') {
    include '**/*.properties'
    include '**/*.csv'
  }
}
like image 157
Barney Avatar answered Sep 23 '22 21:09

Barney