I have a java project. Inside the project I have package “com” and “com.sql”, I used gradle to compile, I didn’t see com.sql package in my build folder.
How can I include everything to build?
Inside com.sql are only sql files.
I have a java project. Inside the project I have package “com” and “com.sql”, I used gradle to compile, I didn’t see com.sql package in my build folder.
How can I include everything to build?
Inside com.sql are only sql files.
You should declare your sql-package as a ressource, Have a look at https://gradle.org/docs/current/userguide/java_plugin.html#N11F7B
Hi Carlo
Thanks for your replying.
Can I do it in another way?
If let’s say I have other staff in other packages like com.customer.sql, com.customer.txt and com.product.sql, com.product.txt, I want all of them to be compiled without specify them one by one.
Can you describe what your directory layout for your project is? where com.* and com.sql.* source files, etc are?
Sorry, my bad.
Please get them from github https://github.com/yhjhoo/gradle-Build-Test/tree/master/app
Ah, I see. You’re not talking about compiling com.sql source files, you have files in com/sql that you want in the jar at the end.
Those are usually called ‘resources’. Resources go in src/main/resources and not in src/main/java. Anything in resources gets included in the jar as-is. So if you put your sql file in src/main/resources/com/sql, it’ll end up in /com/sql/ in the jar.
HTH
Hi Sterling
I get understand it. But I still don’t want to organize it in this way. Is there anyway to just include everything in src/main/java folder to compile? And I don’t want to specify them one by one either.
In maven, I could do it in this way:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>
How to do it in gradle way?
The equivalent idea in Gradle is to configure the main sourceSet’s resources.
See the sample here: https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/java/customizedLayout/build.gradle#L17-L19
This adds ‘src/resources’ as a resource directory.
I have solved this issue by adding following setting in my build.gradle.
Although it didn’t copy it to the same path as package com, it packaged together in jar.
sourceSets.main.resources { srcDirs = ["src/main/java"]; include "**/*.*" }