2

There are some externally sourced Java classes that happen to be defined all in the default unnamed package, i.e. there are no package ... statement at the top of the .java source files where these Java classes are defined. I use these as dependencies in my Java project. The few Java classes I write for my project are also placed in the default unnamed package. I use IntelliJ IDEA 13.1 to work on this project and set the .jar file containing the external Java classes as a library and project dependency. However, I don't know how to configure Gradle so it properly handles the dependency. Currently, I just "manually" added a configuration for the project as a regular Java Application. Clicking on 'Run' using the configuration compiles and runs the project OK.

qazwsx
  • 25,536
  • 30
  • 72
  • 106
  • No special configuration is necessary for this. – Peter Niederwieser Jul 24 '14 at 04:32
  • After clicking the default tasks -- is it the right term? -- such as 'buildJava' or 'build' in the Gradle window in IntelliJ IDEA, many errors prints out in the console. The first one is complaining `cannot find symbol \\ symbol : class SomeExternalClass \\location: class MyClass` – qazwsx Jul 24 '14 at 05:56
  • Really, do the right thing, and put all your classes in a package. Using the default package is a bad, bad, bad practice that will only cause you trouble. – JB Nizet Jul 24 '14 at 07:04
  • Have you verified that simply adding packages makes the Gradle build succeed? I'd think it's a different, unrelated problem. – Peter Niederwieser Jul 24 '14 at 10:48
  • No, I don't have the option of adding `package *` statements at the top of the external classes. It's required to stay in the unnamed default package by my superior. Also this fact is unrelated to this technical question. – qazwsx Jul 24 '14 at 16:55
  • Also, the external classes come in as one JAR file. I don't know how to put all the contained classes into a package. – qazwsx Jul 24 '14 at 16:56
  • I was stuck trying to figure out a related compilation issue until I found that [you can’t import classes from the unnamed package](https://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package) – andrewdotn Oct 03 '17 at 22:10

0 Answers0