0

I am working on a Intellij plugin and is my first attempt on Java language to build a "real project". On this plugin I have created a lot of classes (and enums) and, after refactoring the code, I ended up getting to the point where some classes I have created were no longer in use (except for unit tests, that is not packaged together on final package).

My question is: if a class are not need on package anymore, there is some way to it not be package without remove it from project? (Once that I could, futurely, need of this class again.)


Real example:

Finding by usage of UserDataHolderUtil enum on the project:

The .jar contents:

You can note that this enum is used currently only for unit tests, but it is packaged into final package and never is used.

David Rodrigues
  • 12,041
  • 16
  • 62
  • 90
  • usually people have a whole package only for unit test that isn't packaged in the final app :) – Jeremy Grand Jun 02 '17 at 12:03
  • It is done by mark the directory `/tests` as "test source" on Intellij, then it is not packed on final .jar, but unused classes still are. – David Rodrigues Jun 02 '17 at 12:43
  • Some maven-plugin might do what you want. Do you use maven for building ? Gradle ? Ivy ? Ant ? – Jeremy Grand Jun 02 '17 at 12:45
  • 1
    Consider a different approach. Use source control to have a work-in-progress branch to house classes which are no longer needed (for now). Delete the dead code from trunk to keep the project lean and clean. – Andrew S Jun 02 '17 at 13:04
  • @JeremyGrand currently I am using the own Intellij package process, and I really don't know if it uses some of this tools. – David Rodrigues Jun 02 '17 at 13:11
  • @AndrewS I have considered it, but is a hard work to do. Currently my project is very small, but I don't know how I will check things like that on future (each class or method unused). – David Rodrigues Jun 02 '17 at 13:12
  • I think IntelliJ can handle your need to some extent. Cf https://stackoverflow.com/questions/6587729/how-to-use-intellij-idea-to-find-all-unused-code – Jeremy Grand Jun 02 '17 at 13:18
  • Unfortunatelly, if you are creating unit test for each method it consider as "used". :( – David Rodrigues Jun 02 '17 at 14:48

2 Answers2

0

The ususal approach is to organize your types and resources in different source folders. Those can be configured within the module settings of intellij. It's usually grouped in "source", "test source", "resources" and "test resources".

The common organisation on the file system is usually (I think that's a 'de facto' standard, at least maven does it this way)

  • src/main/java
  • src/main/resources
  • src/test/java
  • src/test/resources

The build tool should then be configured correspondingly to package a production-jar and a test-jar (which then uses the production-jar as dependency to run its tests).

Hope this helps,...

slowy
  • 227
  • 1
  • 6
  • I am already doing that, with some small changes, but I specify each directory type, and even it continues to happen. – David Rodrigues Jun 02 '17 at 12:41
  • Actually, it’s not a standard anywhere other than in Maven. I’m not saying that makes it bad, just that it’s merely Maven’s customary structure. Regardless of the actual directory structure used, though, separation of source and tests into different subdirectories is a good idea. – VGR Jun 02 '17 at 13:30
  • @VGR: For completeness: It's the gradle-standard layout, too, I just found out (I'm working in a "gradle project" and I was wondering, why we're using the same structure as mvn). – slowy Jun 02 '17 at 13:46
0

I would create a new module under the same project in IntelliJ IDEA and move all unused types to the new module.

This way, the package hierarchy of the types is retained, and the types remain in the same project, which means that they are included in any refactoring that you might do.

You make the "unused" module depend on the main module of the project, but of course no other module depends on it, so you do not have to include it in the final package.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142