問題:
Maven 2.2.1を使用してモジュラー Web アプリを構築しています。特に、 maven-antrun-pluginを呼び出して、プロパティ ファイルでいくつかの置換を実行します。
これは、ゴールを指定して Maven を起動すると失敗しますclean,install
。ビルドはIllegalArgumentException: Illegal group referenceで失敗します。
私が理解していることから、この例外は のいずれかString.replace()
およびさまざまなメソッドで発生する可能性がMatcher
あり、引数の 1 つの解析エラーを示しています。
誰かがこのコードの欠陥を指摘できますか?
注:このタスクのためにmaven-replacerまたはmaven-ressourcesに切り替えることは許可されていません。
pom.xml のタスクを置き換えます。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>Properties</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<echo message="Switching properties"/>
<property file="${project.build.outputDirectory}/env.properties"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.infoAppender\.File.*=).*$" replace="\1${log4j.appender.infoAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.batchAppender\.File.*=).*$" replace="\1${log4j.appender.batchAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.errorAppender\.File.*=).*$" replace="\1${log4j.appender.errorAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.debugAppender\.File.*=).*$" replace="\1${log4j.appender.debugAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.secuAppender\.File.*=).*$" replace="\1${log4j.appender.secuAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.appender\.perfAppender\.File.*=).*$" replace="\1${log4j.appender.perfAppender.File}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.category\.error.*=).*$" replace="\1${log4j.category.error}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.category\.debug.*=).*$" replace="\1${log4j.category.debug}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.rootLogger.*=).*$" replace="\1${log4j.rootLogger}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/log/log4j.properties" match="(log4j\.logger\.org\.hibernate\.SQL.*=).*$" replace="\1${log4j.logger.org.hibernate.SQL}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/projet.properties" match="(blah\.ihm\.pleinEcran\.actif.*=).*$" replace="\1${blah.ihm.pleinEcran.actif}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/projet.properties" match="(blah\.version.*=).*$" replace="\1${blah.version}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/projet.properties" match="(blah\.developpement.*=).*$" replace="\1${blah.developpement}" byline="true"/>
<replaceregexp file="${project.build.outputDirectory}/properties/infrastructure.properties" match="(erreur\.technique\.mode\.prod.*=).*$" replace="\1${erreur.technique.mode.prod}" byline="true"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>Test-properties</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<echo message="Replacing in test properties"/>
<property file="${project.build.testOutputDirectory}/env.properties"/>
<replaceregexp
file="${project.build.testOutputDirectory}/jndi.properties"
match="(org\.osjava\.sj\.root.*=).*$"
replace="\1${org.osjava.sj.root}"
byline="true"/>
<copy overwrite="true" file="${project.build.testSourceDirectory}/hibernate.cfg.ic.xml" tofile="${project.build.testOutputDirectory}/hibernate.cfg.test.xml"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.3-1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-trax</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</plugin>
出力:
[WARNING] DEPRECATED [tasks]: Use target instead
[INFO] [antrun:run {execution: Properties}]
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
main:
[echo] Switching properties
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: java.lang.IllegalArgumentException: Illegal group reference
around Ant part ...<replaceregexp replace="\1${log4j.appender.infoAppender.File}" byline="true" file="REDACTED\mvntarget\classes/properties/log/log4j.properties" match="(log4j\.appender\.infoAppender\.File.*=).*$"/>... @ 6:232 in REDACTED\mvntarget\antrun\build-main.xml
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An Ant BuildException has occured: java.lang.IllegalArgumentException: Illegal group reference
around Ant part ...<replaceregexp replace="\1${log4j.appender.infoAppender.File}" byline="true" file="REDACTED\mvntarget\classes/properties/log/log4j.properties" match="(log4j\.appender\.infoAppender\.File.*=).*$"/>... @ 6:232 in REDACTED\mvntarget\antrun\build-main.xml
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException has occured: java.lang.IllegalArgumentException: Illegal group reference
around Ant part ...<replaceregexp replace="\1${log4j.appender.infoAppender.File}" byline="true" file="REDACTED\mvntarget\classes/properties/log/log4j.properties" match="(log4j\.appender\.infoAppender\.File.*=).*$"/>... @ 6:232 in REDACTED\NAEMetier\mvntarget\antrun\build-main.xml
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:355)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: REDACTED\mvntarget\antrun\build-main.xml:6: java.lang.IllegalArgumentException: Illegal group reference
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:327)
... 19 more
Caused by: java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
at org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp.substitute(Jdk14RegexpRegexp.java:116)
at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.doReplace(ReplaceRegExp.java:289)
at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.doReplace(ReplaceRegExp.java:357)
at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.execute(ReplaceRegExp.java:491)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
... 25 more