1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.jar;
20
21 import java.io.File;
22
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugins.annotations.LifecyclePhase;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.plugins.annotations.ResolutionScope;
28
29
30
31
32
33
34
35
36 @Mojo(
37 name = "test-jar",
38 defaultPhase = LifecyclePhase.PACKAGE,
39 requiresProject = true,
40 threadSafe = true,
41 requiresDependencyResolution = ResolutionScope.TEST)
42
43 public class TestJarMojo extends AbstractJarMojo {
44
45
46
47
48
49 @Parameter(property = "maven.test.skip")
50 private boolean skip;
51
52
53
54
55 @Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
56 private File testClassesDirectory;
57
58
59
60
61 @Parameter(defaultValue = "tests")
62 private String classifier;
63
64
65
66
67 @Override
68 protected String getClassifier() {
69 return classifier;
70 }
71
72
73
74
75 @Override
76 protected String getType() {
77 return "test-jar";
78 }
79
80
81
82
83 @Override
84 protected File getClassesDirectory() {
85 return testClassesDirectory;
86 }
87
88
89
90
91 @Override
92 public void execute() throws MojoExecutionException {
93 if (skip) {
94 getLog().info("Skipping packaging of the test-jar");
95 } else {
96 super.execute();
97 }
98 }
99 }