I am trying to prevent dependency checking in java compiler, I use command line compilation,is there any way to tell javac compiler not to check dependency while compiling a java file ?
-
4dependency checking? like "dependency" when a class depends in other one? how would it compile then?Alonso Dominguez– Alonso Dominguez2013-01-29 13:56:25 +00:00Commented Jan 29, 2013 at 13:56
-
3Delete all dependencies ... :DFildor– Fildor2013-01-29 13:56:42 +00:00Commented Jan 29, 2013 at 13:56
-
why would you wish to do this?Jon Taylor– Jon Taylor2013-01-29 13:56:51 +00:00Commented Jan 29, 2013 at 13:56
-
What are you trying to do?Alexis Dufrenoy– Alexis Dufrenoy2013-01-29 13:59:10 +00:00Commented Jan 29, 2013 at 13:59
-
2What you need is a bit of project abstraction & good design, of course you can build a library with common utilities and then provide system-specific implementations in the platform dependent modules. But compile without dependency checking? that's nonsense.Alonso Dominguez– Alonso Dominguez2013-01-29 15:11:30 +00:00Commented Jan 29, 2013 at 15:11
3 Answers
... is there any way to tell javac compiler not to check dependencies while compiling a java file ?
The simple answer is No.
Suppose you have some class A that wants to call some method m defined by class B. In order to successfully compile A, the compiler needs to know that B is a real class, that it defines the method m, that it has the expected number and type of arguments, what checked exceptions it throws, and what type of value it returns. Without this information about B, the compiler cannot compile A.
And this propagates to the project level. If a class in project P depends on a class in project Q, the compiler must have that class (at least) in order to compile the class in P.
In short, no such compiler option exists, and it is hard to see how it could be implemented it it did.
1 Comment
If you're two projects are dependent on each other then they are really one project and must be built together. If the relationship is a one-way relationship then you will still need to build the dependent project first and then have the results of the project on the classpath when building the second project.
Most IDEs have capabilities to manage this. In Eclipse you can mark that one project depends on another project and the dependent project's output files will be added to the classpath of the other. Typically all dependencies are built and packaged as jars and those jar files are placed onto the classpath when compiling parent projects.
Building code without having access to the dependencies is very difficult and not recommended. In some cases it can be possible. Eclipse has built their own incremental Java compiler so that they do not have to recompile the entire project each time a single file is modified. You can read more about it here but in order to use such a compiler you will likely have to do a lot of work.
UPDATE to reflect your new edit:
In order to build a common library that common library must not depend on any classes in your platform-specific sections. As Peter Rader has mentioned the typical way of doing that is by using interfaces. For example, your common library can have an EventListener interface which receives events. In your platform specific libraries you can implement that interface and process the events according to the specific platform. Since your common library only depends on the EventListener class and not the specific implementations it does not need those specific classes when it compiles.