Skip to content

Instantly share code, notes, and snippets.

@nikuyoshi
Last active August 29, 2015 14:06
Show Gist options
  • Save nikuyoshi/2ae8079f75ab57bbd879 to your computer and use it in GitHub Desktop.
Save nikuyoshi/2ae8079f75ab57bbd879 to your computer and use it in GitHub Desktop.
Mavenコトハジメ

Mavenを初めて使ってみた

Javadocの@sinceなどを自動生成したいと思って、Mavenを始めました。 きっかけは下記の記事。

"java - Automatic @since javadoc tag for releases - Stack Overflow" http://stackoverflow.com/questions/3417243/automatic-since-javadoc-tag-for-releases

インストール(Maven本体、m2e)

公式ページからtarballをダウンロード、解凍、任意の場所(~/workspace直下)に置いておきました。 後々面倒くさいので、いつも通りシェルにパスを通して終わり。

# Maven
export PATH=$PATH:/Users/nikuyoshi/workspace/apache-maven-3.2.3/bin/

Eclipse上でxmlを修正したいため、m2eも導入。 Eclipse Marketplaceで「maven」で検索すると上位に出てきます。 m2eは、公式が薦めているプラグインのため、迷わず導入しました。 http://maven.apache.org/eclipse-plugin.html

pom.xmlの作成、実行

Twitter4jのpom.xmlを参考(https://github.com/yusuke/twitter4j/blob/master/twitter4j-core/pom.xml)に しながら、自分なりのpom.xmlを作っていきました。

<?xml version="1.0"?>
<project
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.fhpx</groupId>
  <artifactId>500px-java-core</artifactId>
  <version>0.9.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>500px-java-core</name>
  <licenses>
    <license>
      <name>MIT License</name>
      <url>http://opensource.org/licenses/MIT</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <scm>
    <url>https://github.com/nikuyoshi</url>
    <connection>scm:git:git://github.com:nikuyoshi/500px-java-api.git</connection>
    <developerConnection>scm:git:git://github.com:nikuyoshi/500px-java-api.git
        </developerConnection>
  </scm>
  <developers>
    <developer>
      <id>nikuyoshi</id>
      <name>Hiroki UCHIDA</name>
      <email>[email protected]</email>
      <url>https://github.com/nikuyoshi</url>
      <roles>
        <role>developer</role>
      </roles>
      <timezone>-9</timezone>
    </developer>
  </developers>
  <issueManagement>
    <system></system>
    <url></url>
  </issueManagement>
  <dependencies>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <id>javadoc-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <failOnError>false</failOnError>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <charset>UTF-8</charset>
          <show>public</show>
        </configuration>
        <version>2.8.1</version>
      </plugin>
    </plugins>
  </build>
</project>

こんな感じであっさり書けました。 実行結果は以下の通り。 Javadocの修正をしています。

⚡ mvn javadoc:fix
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-javadoc-plugin/2.8.1/maven-javadoc-plugin-2.8.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-javadoc-plugin/2.8.1/maven-javadoc-plugin-2.8.1.pom (15 KB at 4.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-javadoc-plugin/2.8.1/maven-javadoc-plugin-2.8.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-javadoc-plugin/2.8.1/maven-javadoc-plugin-2.8.1.jar (289 KB at 303.8 KB/sec)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building 500px-java-core 0.9.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom (10 KB at 34.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar (42 KB at 143.1 KB/sec)
[INFO]
[INFO] >>> maven-javadoc-plugin:2.8.1:fix (default-cli) > compile @ 500px-java-core >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 500px-java-core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ 500px-java-core ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.1/maven-shared-utils-0.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.1/maven-shared-utils-0.1.pom (4 KB at 14.1 KB/sec)
---略---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING]
[WARNING]     WARRANTY DISCLAIMER
[WARNING]
[WARNING] All warranties with regard to this Maven goal are disclaimed!
[WARNING] The changes will be done directly in the source code.
[WARNING] The Maven Team strongly recommends the use of a SCM software BEFORE executing this goal.
[WARNING]
[INFO] Are you sure to proceed? [Y]es [N]o
Y
[INFO] OK, let's proceed...
[WARNING] No previous artifact has been deployed, Clirr is ignored.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:48 min
[INFO] Finished at: 2014-09-04T03:48:26+09:00
[INFO] Final Memory: 15M/38M
[INFO] ------------------------------------------------------------------------

で、肝心要のJavadocがどうなってるのか確認したのですが、@versionとかに期待しているものが入っていないため、まだ修正が必要そうです。 うへー。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment