Closed chjan closed 6 years ago
The default is to have sourceSets.main.java.srcDirs == ['src/main/java']
in Gradle, so you don't have to set it. That said, setting it explicitly shouldn't be an issue.
The only way I can see what you described happening is that if you set sourceSets.main.java.srcDirs == ['src']
, in which case this is the correct behaviour. Anyway, what you say implies that NB believes that the source root is the "src" directory. Could it be that you set it so in your script and forgot to reload the project since then?
No, I think lack of reload is not the reason, I have tried restart NB. Yes, I have come to understand that src/main/java is default, confirmative. I do not set sourceSets.main.java.srcDirs == ['src/main/java'], I set almost nothing.
I have compared to Android Studio that does not have this problem in its Android context, probably because the AndroidManifest file is used to instruct the root of the source path to src/main/java.
So, is there a way to make NB understand that this is the root of the source?
One cumbersome solution that works is to do the following under sourceset {main { resources output.resourcesDir = "build/classes/resources/com/hdsl/streamer/resources", which forces correct placement.
Perhaps the plugin could sniff the path for classes and create the same path for resources?
I add the whole build.gradle, just in case you can see anything (sorry, the code <> did not work)
`buildscript { repositories { jcenter() dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1' } } }
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java'
//probably not necessary, se the jar{} section if (!hasProperty('mainClass')) { ext.mainClass = 'main.java.com.hdsl.streamer.ZappPcGui' }
jar { manifest { attributes( //'Class-Path': configurations.compile.collect { it.getName() }.join(' '), 'Main-Class': 'main.java.com.hdsl.streamer.ZappPcGui' ) } }
repositories { mavenCentral() jcenter() { url "http://jcenter.bintray.com/" }
flatDir {
dirs 'libs'
}
}
sourceSets { main {
java {
//srcDirs = ['src']
}
resources {
//output.resourcesDir = "build/classes/java/main/com/hdsl/streamer/resources"
}
}
}
version '1.0'
//Moved from HDSLClientServers to conform all projects sourceCompatibility = '1.8'
[compileJava, compileTestJava].options.encoding = 'UTF-8'
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':HDSLClientServer')
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '$rootProject.ext.gsonVersion'
// https://mvnrepository.com/artifact/javax.jmdns/jmdns
compile group: 'javax.jmdns', name: 'jmdns', version: "$rootProject.ext.jmdnsVersion"
}
//Create a single JAR including dependencies stated in this build file shadowJar { //Use default name to avoid two jar files, on thin and one fat //baseName = 'ZappLaptop' classifier = '' }
//This is mandatory to create the shadowJar file with all libs project.tasks.assemble.dependsOn project.tasks.shadowJar
`
It should work (I have never seen it not to work). I think something somewhere cached you setting the source root to "src". You should try to delete the NB cache and restart NB. But first, confirm that your Gradle build script is fine by printing sourceSets.main.java.srcDirs
.
Sorry for bothering you, this issue may be closed. The reason was that the Netbeans Clean function is partly broken and has been for years. I will explain in case it could help others:
First, there was an error in that NB found inconsistency between package name and actual folder structure, i.e. that standard Gradle assumes the src/main/java top folders. This could be a cache issue, I don't know.
Therefore, I removed main.java from the package name in the "package explorer". Therefore, NB automatically and without saying anything is rearranging the folders accordingly, to src/com
Therefore, and perhaps I did some other things too, there are old empty source folders remaining.
A clean&build does not remove these empty folders, nor is NB providing any notifications.
I finally found the /source roots/delete empty source roots function. This removed these empty folders, and then it worked again.
I don't know if your plugin has a vulnerability in that it will include empty folders. If so, perhaps arrange it so that empty folders are completely disregarded and not put into the build folder after build?
If it is NB, then this thread could be of value. I have never succeeded in having an error corrected via the NB issues page.
This is my best guess as to what happened.
I don't I understand why you say that "clean" is broken. It is not supposed to delete empty source folders. In fact - for Gradle projects - it will simply execute the "clean" task of Gradle which will remove the "build" folder. As for what appears in the "build" folder: It is not a plugin thing, only Gradle tasks will create build output in there. I can't see your setup, so I don't want to guess what went wrong, and to be honest I don't think I completely understand what exactly you did. Most certainly, empty source roots are not a problem as they are quite common. Maybe you accidentally created a directory in the source root with "." in its name?
If for nothing else, I say "Broken" because at one point of time, the package inconsistency is present. 2 hours later, it is accepted, and the folder structure is the same. Somehow, there is a lag creating havoc. You could be right about a ".", but that's a guess. Thanks for your help
It could be that this is a question that should be asked in Gradle forums, but perhaps there is a simple solution?
I would like to:
sourceSets { main {
java { srcDirs= ["src/main/java"] }
But if I delete the main.java part of the package name (according to 1), then this has the consequence that the /main and /java folders are deleted and the /com folder is positioned directly under /src
Therefore, during build, Gradle is unable to find the source files.
On the other hand, if I keep the main.java in the package name, the syntax check reports inconsistency if the source file does not include main.java in the package name.
Therefore, in order to read resources, the only way I found was to put resources under
src/main/resources/main/java/com/myproject (i.e. need to put in the mina/java)
Now the resources are found during runtime according to getClass().getResource( "....")
Is there a way to make both 1 and 2 happen, or are they mutually exclusive?
Many thanks for any help. I add that I perceive this plugin as excellent work, I just need to learn how to use it properly.