When to use which scope

I keep getting confused about which artifact scope to use: compile, test, or runtime?  So here’s a little algorithm to help me (it’s a conservative algorithm, trying to depend on libraries only to the extent necessary):

  • If the artifact is not not needed by the production code but only by tests, use test scope.
  • Otherwise, if production code needs the artifact at runtime but does not need to code against its classes and interfaces (for instance, if all references to the artifact in production code are in Spring bean files), use runtime scope.
  • Otherwise, if the production code needs to code against the artifact’s classes and interfaces, use compile scope.

So in my algorithm you consider test scope first, and open it up to runtime or compile scope only if necessary.

Advertisements

  1. #1 by Magnus on December 18, 2008 - 1:45 pm

    And then you have “provided”, when you need it to compile and test, but don’t want to deploy it since its provided by the app server or so…

  2. #2 by danielmeyer on December 18, 2008 - 2:24 pm

    Right, but I don’t get as confused about that one so I left it out. : )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s