tech_memo / maven


tech_memo

ローカルリポジトリにjarを登録

HTTPとHTTPS両方のプロキシを使う

  • 参照 : http://takezoe.hatenablog.com/entry/20110102/p2
  • HTTPとHTTPSのうち、片方しかsettings.xmlに設定できないので、もう片方は以下のように、VMの起動オプションで指定する
    set MAVEN_OPTS=-Dhttps.proxyHost=<IP> -Dhttps.proxyPort=<PORT>

オフライン環境でSpringの依存ライブラリを一つのjarにまとめる

ソースをdeploy

  • pom.xmlに以下のpluginを追加する。<phase>をdeployと記載しているサイトもあるが、リポジトリにuploadされなかった。
     <build>
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-source-plugin</artifactId>
           <executions>
             <execution>
               <id>attach-sources</id>
               <goals>
                 <goal>jar</goal>
               </goals>
               <phase>verify</phase>
             </execution>
           </executions>
         </plugin>
       </plugins>
     </build>
  • ソースのダウンロードはdepencencyにclassifier要素を記載する
    		<dependency>
    		  <groupId>myapp.client</groupId>
    		  <artifactId>client-sdk</artifactId>
    		  <version>1.0.0</version>
    		</dependency>
    		<dependency>
    		  <groupId>myapp.client</groupId>
    		  <artifactId>client-sdk</artifactId>
    		  <version>1.0.0</version>
    		  <classifier>sources</classifier>
    		</dependency>

build時に、dependencyのjarファイルを常にupdateする

  • デフォルトは1日1回しか更新されない。以下で毎回更新されるようにできる。
       <repositories>
           <repository>
               <id>nexus</id>
               <name>Team Nexus Repository</name>
               <url>http://nexusserver/nexus/content/groups/public</url>
               <snapshots>
                   <updatePolicy>always</updatePolicy>
               </snapshots>
           </repository>
       </repositories>

build成果物をSVNに自動コミット

  • pom.xmlにattrun-pluginを追加し、下記のように記述することでSQL ScriptのZIPを
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-antrun-plugin</artifactId>
       <version>1.6</version>
       <goals>
           <goal>run</goal>
       </goals>
       <configuration>
           <tasks>
               <mkdir dir="${project.build.directory}/checkout"/>
               <exec executable="svn">
                   <arg value="checkout" />
                   <arg value="--username" />
                   <arg value="svnuser" />
                   <arg value="--password" />
                   <arg value="svnuser" />
                   <arg value="http://svnserver/shipment/branches/build" />
                   <arg value="./target/checkout" />
               </exec>
               <!-- 略 -->
           </tasks>
       </configuration>
    </plugin>

Nexus

手動デプロイ

m-nawata@silver02% mvn deploy:deploy-file -Durl=http://nexuserver/nexus/content/repositories/thirdparty -DrepositoryId=nexus -Dfile=./aaa.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar

mvn command option

pom.xmlのversionの一斉変更

mvn versions:set -DnewVersion=x.x.x.x

Test実行スキップ

mvn install -DskipTests=true

Test実行&コンパイルスキップ

mvn install -Dmaven.test.skip=true

mvn testでのテストクラス指定

mvn test -Dtest=classname

mvn testでテストメソッドを指定

  • maven-surefire-pluginのバージョンが2.7.3以上じゃないとだめらしい
  • maven 3.2.5であれば特にplugin指定なしでもできた
    mvn test -Dtest="myapp.test.MyTest#testHoge"
    # ↑
    # シェル環境だとコメントアウトと認識されるので、クォートでくくること

Eclipseプロジェクトへの変換