View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.jar;
20  
21  import javax.inject.Inject;
22  
23  import java.io.File;
24  import java.util.Map;
25  
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.plugins.annotations.LifecyclePhase;
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.apache.maven.plugins.annotations.Parameter;
30  import org.apache.maven.plugins.annotations.ResolutionScope;
31  import org.apache.maven.project.MavenProject;
32  import org.apache.maven.project.MavenProjectHelper;
33  import org.apache.maven.toolchain.ToolchainManager;
34  import org.codehaus.plexus.archiver.Archiver;
35  
36  /**
37   * Build a JAR from the current project.
38   *
39   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
40   * @version $Id$
41   */
42  @Mojo(
43          name = "jar",
44          defaultPhase = LifecyclePhase.PACKAGE,
45          requiresProject = true,
46          threadSafe = true,
47          requiresDependencyResolution = ResolutionScope.RUNTIME)
48  public class JarMojo extends AbstractJarMojo {
49      /**
50       * Directory containing the classes and resource files that should be packaged into the JAR.
51       */
52      @Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
53      private File classesDirectory;
54  
55      /**
56       * Classifier to add to the artifact generated. If given, the artifact will be attached
57       * as a supplemental artifact.
58       * If not given this will create the main artifact which is the default behavior.
59       * If you try to do that a second time without using a classifier the build will fail.
60       */
61      @Parameter
62      private String classifier;
63  
64      @Inject
65      JarMojo(
66              MavenProject project,
67              MavenSession session,
68              ToolchainsJdkSpecification toolchainsJdkSpecification,
69              ToolchainManager toolchainManager,
70              Map<String, Archiver> archivers,
71              MavenProjectHelper projectHelper) {
72          super(project, session, toolchainsJdkSpecification, toolchainManager, archivers, projectHelper);
73      }
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      protected String getClassifier() {
80          return classifier;
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      protected String getType() {
88          return "jar";
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      protected File getClassesDirectory() {
96          return classesDirectory;
97      }
98  }