maven備忘録

Build時間短縮
https://b.chiroito.dev/entry/2024/04/03/163403

mvn install -pl <使いたいモジュールまでのパス> -am
mvn install -rf :ビルドを再開したいモジュール
mvn -f <モジュールまでのパス> clean install
  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <maven.compiler.source>${java.version}</maven.compiler.source>
  </properties>
    • テストのメソッド指定うまくいかない時メソッド名の最後に * つけると動くかも
mvn clean test -Pintegration-tests -Dtest=GlobalQuartzDBTimerServiceTest#testTimerStartMemoryLeak*

パラメータ指定の場合

mvn clean test -Pintegration-tests -Dtest=GlobalQuartzDBTimerServiceTest#testTimerStartMemoryLeak[0]

mvn clean test -Dtest=NotTest#testNegatedConstaintInNot[KieBase\ type=CLOUD_IDENTITY_MODEL_FLOW]

とか

surefire のバージョンが古いとうまくいかないので

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.1</version>
      </plugin>

とかつける


http://maven.apache.org/settings.html
http://maven.apache.org/ref/3.1.1/maven-settings/settings.html

pluginのversion忘れるな。 maven-ear-plugin の が動かなかったりするゾ!

  • -DskipTests は test-compileやる -Dmaven.test.skip=true は test-compile もスキップ
  • -Dmaven.test.failure.ignore=true ランダムに落ちるテストがある場合、こっちで全体像を確認する
  • ArtifactResolutionException / resolution will not be reattempted until the update interval of/ Original error: Could not transfer artifact とか出たら
find ~/.m2  -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;

そんで、pom.xmlを書き換え、セーブ(スペース足して削除とかでいい)

  • ./wsdl4j/wsdl4j/1.6.3.redhat-1/aether-b76d467f-ebcb-43e9-b091-1002bb0cd5f4-wsdl4j-1.6.3.redhat-1.jar.sha1-in-progress

- "in-progress" で検索 (find ~/.m2/repository | grep "in-progress")。あったらディレクトリごと削除

    • snapshot の force update ならオプション -U
  • GWT compile で OutOfMemoryError
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <configuration>
...
          <extraJvmArgs>-Xmx4096m -XX:MaxPermSize=256m</extraJvmArgs>
...
        </configuration>
...
      </plugin>
mvn install:install-file -Dfile=myjar.jar -DgroupId=org.example -DartifactId=myexample -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dpackaging=pom -Dfile=xxx-parent-0.1.0.pom -DpomFile=xxx-parent-0.1.0.pom

mvn install:install-file -Dfile=jbpm-flow-builder-6.5.0.Final-redhat-23-RHBPMS-5190.jar -Dsources=jbpm-flow-builder-6.5.0.Final-redhat-23-RHBPMS-5190-sources.jar -DgroupId=org.jbpm -DartifactId=jbpm-flow-builder -Dversion=6.5.0.Final-redhat-23-RHBPMS-5190 -DpomFile=jbpm-flow-builder-6.5.0.Final-redhat-23-RHBPMS-5190.pom -Dpackaging=jar
Maven also has a special qualifier, the SNAPSHOT, which indicates the artifact is created while the project is under active development. When you install/release an artifact or fetch one from a remote repo, maven expand this SNAPSHOT suffix with a date(UTC format)-time-buildnumber pattern. So for an artifact like myjar-1.0.0-SNAPSHOT.jar the result would be myjar-1.0.0-20100219.141012-1.jar. And If you install a SNAPSHOT artifact to your local repository it will not get converted to the date-time format to sake of your harddisk, not filling it up with snapshot versions. 

checkstyleうざい

  <properties>
    <checkstyle.skip>true</checkstyle.skip>
  </properties>

formatter skip

-Dformatter.skip=true

surefire でリモートデバッグ

https://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html

mvn -Dmaven.surefire.debug test
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test

Unit Test に JVM オプションを与える

 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.9</version>
    <configuration>
     <argLine>-Dfile.encoding=US-ASCII</argLine>
    </configuration>
   </plugin>
  </plugins>
 </build>

maven debug

export MAVEN_OPTS="$MAVEN_OPTS -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=18787"

Win

set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=18787

enforcer

[WARNING] Rule 0: org.commonjava.maven.enforcer.rule.EnforceManagedDepsRule failed with message:
The following 1 dependencies are NOT using a managed version:

version の上書きが必要で、WARNが出てもビルドしたいならば、

mvn clean install -DskipTests -Denforcer.fail=false

logback

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>1.2.3</version>
    </dependency>

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- %l lowers performance -->
            <!--<pattern>%d [%t] %-5p %l%n  %m%n</pattern>-->
            <pattern>%d [%t][%c] %-5p %m%n</pattern>
        </encoder>
    </appender>
    <logger name="org.kie" level="debug"/>
    <logger name="org.drools" level="debug"/>
    <root level="info"><!-- TODO We probably want to set default level to warn instead -->
        <appender-ref ref="consoleAppender"/>
    </root>
</configuration>

junit

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

exec:java

mvn clean package
mvn exec:java -Dexec.mainClass=com.sample.SerializeTest
mvn exec:java -Dexec.mainClass=com.sample.DeserializeTest

mvn clean package exec:java -Dexec.mainClass=com.sample.MyTest -Dexec.classpathScope=test
kie-maven-plugin で single test
mvn verify -Dinvoker.test=kie-maven-plugin-test-kjar-10-default

plugin を debug ログ出力
mvn clean package -Dorg.slf4j.simpleLogger.log.org.drools.modelcompiler.builder=debug