Reputation: 185
I have a Jackson services project in Eclipse that uses Maven for the build process, and I have several "test only" endpoints that are necessary for the unit tests, but should be removed for the public build. Is there an annotation, or other configuration property I can set so that in the build process (after the unit tests pass), the endpoint will not be deployed?
For example, I have a method like:
@GET
@Path("/{user}/addresses")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> getUserAddresses(...){ ... }
And when this is published, user addresses will come from a 3rd party system, but for testing, we need a way to add an address, so i have
@POST
@Path("/{user}/address")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> createAddress(
but I want the 2nd method to never exist on the live server.
Upvotes: 1
Views: 92
Reputation: 140041
I would just put the "test only" classes in src/test/java
. There is no rule that the only things that can appear in src/test/java
are unit tests only.
This way you have nothing extra to configure with Maven to exclude classes.
Alternatively, you could tell the maven-jar-plugin or maven-war-plugin to exclude specific classes from being packaged in the final artifact, but this has the downside of not being able to catch a case where you accidentally import one of the "test only" classes in a real class and thus you ship something in your jar/war that will cause a NoClassDefFoundError. If you place the "test-only" classes in src/test/java
instead, and therefore ensure they are only on the test classpath, this accidental import problem will not be possible (compilation of the main code will fail).
Upvotes: 1