Maven配置文件具有属性变量

时间:2016-02-17 22:07:38

标签: maven variables profile

我正在研究MAVEN个人资料,我有一个关于使用变量设置属性的问题。目前,我正在使用以下配置:

var withUglify = false;

gulp.task('build', function(){
   // Use something like ``gulp-if`` to conditionally uglify.
})

gulp.task('buildWithoutUglify' function(){
   withUglify = true;
   gulp.start('build');
})

gulp.task('watch', function(){
    gulp.watch(someFilePath, ['buildWithoutUglify'])
})

我的问题是这个;有可能以某种方式使用一个带有变量的配置文件来完成相同的工作,类似于:

<profile>
  <id>Action type D restriction</id>
  <activation>
    <property>
      <name>actionType</name>
      <value>D</value>
    </property>
  </activation>
  <properties>
    <restriction.actionType>D</restriction.actionType>
  </properties>
</profile>

<profile>
  <id>Action type W restriction</id>
  <activation>
    <property>
      <name>actionType</name>
      <value>W</value>
    </property>
  </activation>
  <properties>
    <restriction.actionType>W</restriction.actionType>
  </properties>
</profile>

或类似的东西。

2 个答案:

答案 0 :(得分:1)

也许你想要这样的东西

margin-bottom: -500px;
z-index: -1;

答案 1 :(得分:0)

谢谢Tunaki。这就是诀窍。现在我的设置是:

<project>
...
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <ActionType/>
</properties>
...
<profiles>
    <profile>
        <id>Action-type profile</id>
        <activation>
            <property>
                <name>actionType</name>
                <value>[D,W]</value>
            </property>
        </activation>
    </profile>
</profiles>
...
<build>
    <pluginManagement>
      <plugins>
        <plugin>
            <groupId>properties.plugin</groupId>
            <artifactId>Lazaruss-maven-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>

            <configuration>
                <actionType>${actionType}</actionType>
            </configuration>
            ...
        </plugin>
      </plugins>
    </pluginManagement>
</build>

使用命令运行它:

mvn groupId:artefactId:version:goal -DactionType=W

它现在将我班级中的变量设置为W:)

PS:注意我班级中的变量也被命名为'actionType'