Reputation: 4137
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 ?
Upvotes: 3
Views: 1679
Reputation: 718708
... 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.
Upvotes: 5
Reputation: 43807
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.
Upvotes: 2
Reputation: 1974
If you have dependencies, they will always be checked and give warnings, but your classes will be compiled anyway.
Often frameworks offer an api.jar that contains interfaces and enums.
Upvotes: 0