Using the source of a dep module during debug
I cannot step into source for a dependent module during tomcat debug session.
I'm not sure this is a result of the way I have modules configured or a bug in IntelliJ 9.0.2. I did have this working in past (non-Artifact) versions so I suspect this is related to either Artifact setup or maybe Dependency Scope.
During tomcat debug, when I step into a class located within a dependent module, it does not go to module source; it steps into the decompiled jar file and claims "source not found." If I ctrl-click the method call, it brings me to source as expected. In webapp module config, I have the dependencies in the correct order: the module dependency comes before the jar library.
I've tried several variations within the Dependencies config: ticking and unticking Export, changing Scope from Compile to Runtime to Provided. I don't think these settings should matter anyway, although I must confess confusion over the Export checkbox. Side question: what does the Export checkbox really control?
My project is relatively complicated with several tomcat-based webapp modules and common library modules. For example, here are modules: webapp1, webapp2, webcore, core. webapp1 depends on webcore and core along with its own module library containing both 3rd party jars AND packaged jars for both webcore and core. Same for webapp2. webapp1 does not depend on webapp2 and vice-versa.
For webapp1 module, the Dependencies look like the following, in order:
core a module dependency with Scope=Provided.
webcore a module dependency with Scope=Compile
webapp1-lib a module library with Scope=Compile. Contains jar directories of 3rd party jars and the jars of both core and webcore.
Tomcat an app server library with Scope=Provided. Contains lib jar directories for installed Tomcat 6 and some custom container libs, such as jstl-1.2.jar.
When I debug "webapp1" as a tomcat instance, I have several breakpoints in the webapp1 code and the webcore code. When I stop in a webapp1 class at a call into a webcore class, if I step into the webcore class's method, it takes me to the jar located in webapp1-lib and not the source located in module "webcore."
This project/module config used to work in older versions of IntelliJ 9.
I appreciate any pointers on this type of issue or if this is a known bug. Thanks.
请先登录再写评论。
Hello Rick
> webapp1-lib a module library with Scope=Compile. Contains jar directories of 3rd party jars and the jars of both core and webcore.
This is the reason. According to the description you gave, I suspect that jars containing compiled classes from core and webcore modules are attached to these modules as a jars.
These jars should be removed from dependencies completely. Dependencies between modules should be used instead. For example, if "webcore" depends on "core", you in project settings there is no need to add core.jar in the list of dependencies of "webcore" module. The right way will be adding a module dependency on "core" module.
Thanks.
As I mentioned, this used to work prior to Artifacts being introduced. The order of the dependencies was important and it would use the source of a dependency module over any jar that came after it in the dependencies list. This priority-order feature was very handy when one wants to include jar directories over individual class dependencies.
So, I did what you suggested, converted from a jar directory to individual class dependencies in webapp1-lib and then did not include either core.jar and webcore.jar. Did this work, was I able to step into the code for webcore while debugging webapp1? No. What intellij did was step into the decompiled code from the jar included in webapp2! As I said, webapp1 and webapp2 are independent except they just happen to depend on the same modules/jars of webcore and core. If I'm debugging webapp1, then webapp2 should not be involved. Maybe if I was running both webapp1 and webapp2 during the same tomcat session, but even then, I think not. Their dependency chain is their own.
I've noticed this before in a more general way. IntelliJ will not keep the code separate for independent modules when the package structure is the same. It might pull up code from an unrelated module during both browsing code and during debug sessions. My expectation is that IntelliJ can handle independent application modules in the same project and find the applicable code as defined in the Dependencies structure (in priority order). In my 4+ years of using IntelliJ, I've never noticed unexpected behavior in this regard, until recently.
I imagine that the use case of having multiple compatible but independent webapps (and apps) modules in IntelliJ is fairly common and certainly useful, and that IntelliJ really should find the right code for each.
Now, I did solve my immediate problem so I can now step into source code instead of being given jars' decompiled classes. I removed the core and webcore jars from ALL webapps' dependencies, e.g. webapp1 and webapp2. They depend on the core module and the webcore modules with no core.jar nor webcore.jar anywhere in their Dependencies.
This is exactly what I suggested in my post. In general, if there is a dependency between module A and B (A depends on B), the right way to configure dependencies is to set up a module dependency rather than add to A's dependency list a jar containing compiled classes of B.