JetBrains IntelliJ IDEA12でMavenプロジェクトのテンプレートを作成しようとしています。
私の目標は、テンプレート内の事前定義されたMavenプロパティをエスケープすることです。残念ながら、構文はテンプレート内のIntelliJのパラメーターと同じです。
オンラインヘルプによると、$
シンボルを$
前に別のシンボルでエスケープできるため、テンプレートは次のようになります(下部のプラグイン部分が重要です)。
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
#if (${HAS_PARENT})
<parent>
<groupId>${PARENT_GROUP_ID}</groupId>
<artifactId>${PARENT_ARTIFACT_ID}</artifactId>
<version>${PARENT_VERSION}</version>
#if (${HAS_RELATIVE_PATH})
<relativePath>${PARENT_RELATIVE_PATH}</relativePath>
#end
</parent>
#end
<groupId>${GROUP_ID}</groupId>
<artifactId>${ARTIFACT_ID}</artifactId>
<version>${VERSION}</version>
<!-- global properties -->
<properties>
<jdk.version>1.7</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- set jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>$${jdk.version}</source>
<target>$${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
${END}
</project>
ただし、このテンプレートを使用すると、出力は次のようになります。
<build>
<plugins>
<!-- set jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>$JDK.VERSION$</source>
<target>$JDK.VERSION$</target>
</configuration>
</plugin>
</plugins>
</build>
だから私の質問は:${jdk.version}
代わりにどうやって得ることができ$JDK.VERSION$
ますか、そして文字列をエスケープする適切な方法は何ですか?
IntelliJはテンプレートエンジンとしてApacheVelocityを使用するため、#setを使用して参照を作成できます。
http://velocity.apache.org/engine/releases/velocity-1.6.4/user-guide.html
使用できます
#set( $jdk_version = "${jdk.version}" )
テンプレート内では、$ {jdk_version}で参照するだけです。
次の例をテストできますか?
#set( $jdk_version = "${jdk.version}" )
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
#if (${HAS_PARENT})
<parent>
<groupId>${PARENT_GROUP_ID}</groupId>
<artifactId>${PARENT_ARTIFACT_ID}</artifactId>
<version>${PARENT_VERSION}</version>
#if (${HAS_RELATIVE_PATH})
<relativePath>${PARENT_RELATIVE_PATH}</relativePath>
#end
</parent>
#end
<groupId>${GROUP_ID}</groupId>
<artifactId>${ARTIFACT_ID}</artifactId>
<version>${VERSION}</version>
<!-- global properties -->
<properties>
<jdk.version>1.7</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- set jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk_version}</source>
<target>${jdk_version}</target>
</configuration>
</plugin>
</plugins>
</build>
${END}
</project>
それは次の出力を生成していました:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>3</groupId>
<artifactId>4</artifactId>
<version>5</version>
<relativePath>7</relativePath>
</parent>
<groupId>8</groupId>
<artifactId>9</artifactId>
<version>10</version>
<!-- global properties -->
<properties>
<jdk.version>1.7</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- set jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
11
</project>
これがあなたの助けになり、あなたの質問の答えになることを願っています...
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加