maven 2.0 beta 1 リリース(Good Job!!!)

インストール

  1. http://maven.apache.org/maven2/download.html からダウンロード
  2. maven-2.0-beta-1.zip を解凍
  3. set MAVEN2_HOME=d:\dev\maven-2.0-beta-1
  4. set PATH="%MAVEN2_HOME%\bin";%PATH%

リポジトリ

  • "%USERPROFILE%\.m2\repository"
  • mavenのcaheフォルダはなくなってrepositoryに統一
  • mavenのjarsとpomsフォルダはなくなってひとつに

基本機能

>m2 -v
Maven version: 2.0-beta-1

>m2

usage: maven [options] [goal [goal2 [goal3] ...]]

Options:
 -C,--strict-checksums         Fail the build if checksums don't match
 -c,--lax-checksums            Warn if checksums don't match
 -P,--activate-profiles        Comma-delimited list of profiles to
                               activate
 -ff,--fail-fast               Stop at first failure in reactorized builds
 -fae,--fail-at-end            Only fail the build afterwards; allow all
                               non-impacted builds to continue
 -B,--batch-mode               Run in non-interactive (batch) mode
 -cpl,--check-plugin-latest    Force checking of LATEST metadata for
                               plugin versions
 -npl,--no-plugin-latest       Suppress checking of LATEST metadata for
                               plugin versions
 -fn,--fail-never              NEVER fail the build, regardless of project
                               result
 -up,--update-plugins          Synonym for cpu
 -N,--non-recursive            Do not recurse into sub-projects
 -npr,--no-plugin-registry     Don't use ~/.m2/plugin-registry.xml for
                               plugin versions
 -U,--update-snapshots         Update all snapshots regardless of
                               repository policies
 -cpu,--check-plugin-updates   Force upToDate check for any relevant
                               registered plugins
 -npu,--no-plugin-updates      Suppress upToDate check for any relevant
                               registered plugins
 -D,--define                   Define a system property
 -X,--debug                    Produce execution debug output
 -e,--errors                   Produce execution error messages
 -f,--file                     Force the use of an alternate POM file.
 -h,--help                     Display help information
 -o,--offline                  Work offline
 -r,--reactor                  Execute goals for project found in the
                               reactor
 -s,--settings                 Alternate path for the user settings file
 -v,--version                  Display version information

>rem -g でgoal一覧がでないのは相変わらず痛い

>rem genappのかわり
>m2 archetype:create -DgroupId=hoge -DartifactId=hoge -Dpackage=hoge

>cd hoge

>dir /S /B
E:\temp\m2\hoge\pom.xml
E:\temp\m2\hoge\src
E:\temp\m2\hoge\src\main
E:\temp\m2\hoge\src\test
E:\temp\m2\hoge\src\main\java
E:\temp\m2\hoge\src\main\java\hoge
E:\temp\m2\hoge\src\main\java\hoge\App.java
E:\temp\m2\hoge\src\test\java
E:\temp\m2\hoge\src\test\java\hoge
E:\temp\m2\hoge\src\test\java\hoge\AppTest.java

>type pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hoge</groupId>
  <artifactId>hoge</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

>rem 相変わらずencodingの指定がない
>rem maven-v4_0_0.xsd 登場。これで pom.xml を XML Editor でひらけば Eclipseから補完がきく(XSD pluginがないともちろんだめだが)。Great!!!

>type src\main\java\hoge\App.java
package hoge;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

>type src\test\java\hoge\AppTest.java
package hoge;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}

>m2 compile

>rem depend compile
>m2 test

>rem jarだけだとだめ。
>m2 jar:jar

>dir /S /B *.jar
E:\temp\m2\hoge\target\hoge-1.0-SNAPSHOT.jar

>rem cleanだけだとだめ
>m2 clean:clean

>rem depends compile+test+jar:jar
>m2 package

>dir /S /B *.jar
E:\temp\m2\hoge\target\hoge-1.0-SNAPSHOT.jar

>rem テストをしたくないとき
>m2 -Dmaven.test.skip=true clean:clean package
[INFO] Searching repository for plugin with prefix: 'clean'.
[INFO] -------------------------------------------------------------------------
---
[INFO] Building Maven Quick Start Archetype
[INFO]    task-segment: [clean:clean, package]
[INFO] -------------------------------------------------------------------------
---
[INFO] [clean:clean]
[INFO] Deleting directory E:\temp\m2\hoge\target
[INFO] [resources:resources]
[INFO] [compiler:compile]
Compiling 1 source file to E:\temp\m2\hoge\target\classes
[INFO] [resources:testResources]
[INFO] [compiler:testCompile]
Compiling 1 source file to E:\temp\m2\hoge\target\test-classes
[INFO] [surefire:test]
[INFO] Tests are skipped.
[INFO] [jar:jar]
[INFO] Building jar: E:\temp\m2\hoge\target\hoge-1.0-SNAPSHOT.jar
[INFO] -------------------------------------------------------------------------
---
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------------------
---
[INFO] Total time: 2 seconds
[INFO] Finished at: Sat Sep 17 19:49:21 JST 2005
[INFO] Final Memory: 3M/9M
[INFO] -------------------------------------------------------------------------
---

eclipseプラグイン

>m2 eclipse:eclipse

>dir /B .*
.classpath
.project
.wtpmodules

>type .classpath
<classpath>
  <classpathentry kind="src" path="src/main/java"/>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" rootpath="JRE_SRCROOT" path="JRE_LIB" sourcepath="JRE_SRC"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
</classpath>

>rem M2_REPO 復活!!!(MAVEN_REPOじゃないけど) 当然だな。
>rem リポジトリは junit/junit って冗長だな

>type .project
<projectDescription>
  <name>hoge</name>
  <comment/>
  <projects/>
  <buildSpec>
    <buildCommand>
      <name>org.eclipse.jdt.core.javabuilder</name>
      <arguments/>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>

>type .wtpmodules
<project-modules id="moduleCoreId">
  <wb-module deploy-name="hoge">
    <module-type module-type-id="jst.utility">
      <property name="java-output-path" value="/target/classes"/>
    </module-type>
    <wb-resource deploy-path="/" source-path="src/main/java"/>
  </wb-module>
</project-modules>

>rem ほう。WTPは認められたみたいだね

siteプラグイン

>m2 site:site

>dir /B target\site
css
images
index.html

>rem やっと index.html ができるようになった。一応ちゃんとしたサイトが出来上がる

warを作ってみる

>cd ..

>m2 archetype:create -DgroupId=hoge -DartifactId=hoge2 -Dpackage=hoge -DarchetypeArtifactId=maven-archetype-webapp

>cd hoge2

>dir /S /B
E:\temp\m2\hoge2\pom.xml
E:\temp\m2\hoge2\src
E:\temp\m2\hoge2\src\main
E:\temp\m2\hoge2\src\main\resources
E:\temp\m2\hoge2\src\main\webapp
E:\temp\m2\hoge2\src\main\webapp\index.jsp
E:\temp\m2\hoge2\src\main\webapp\WEB-INF
E:\temp\m2\hoge2\src\main\webapp\WEB-INF\web.xml

>type pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hoge</groupId>
  <artifactId>hoge2</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Webapp Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>hoge2</finalName>
  </build>
</project>

>type src\main\webapp\index.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

>type src\main\webapp\WEB-INF\web.xml
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>

>rem <?xml version="1.0" encoding="UTF-8" ?> が入っていない。やはり 2.3 か。

>m2 war:war

>dir /B target
exported-pom.xml
hoge2
hoge2.war

>rem exported-pom.xml ってなんだ?
>type target\exported-pom.xml
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>hoge</groupId>
  <artifactId>hoge2</artifactId>
  <packaging>war</packaging>
  <name>Maven Webapp Archetype</name>
  <version>1.0-SNAPSHOT</version>
  <url>http://maven.apache.org</url>
  <build>
    <sourceDirectory>E:\temp\m2\hoge2\src\main\java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>E:\temp\m2\hoge2\src\test\java</testSourceDirectory>
    <outputDirectory>E:\temp\m2\hoge2\target\classes</outputDirectory>
    <testOutputDirectory>E:\temp\m2\hoge2\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>E:\temp\m2\hoge2\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>E:\temp\m2\hoge2\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>E:\temp\m2\hoge2\target</directory>
    <finalName>hoge2</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0-beta-1</version>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

>rem ほう。これはいいな。どんなことしているかわかりやすい。