4

I have a property in root pom.xml file: gecko1_8. I want to place this to gwt.xml file.

So I put this property to gwt.xml:

I added the following to build section:

<resources>
  <resource>
  <directory>src/main/resources</directory>
  <filtering>true</filtering>
    <excludes>
      <exclude>VAADIN.themes/*</exclude>
    </excludes>
  </resource>
</resources>

But at the end build failed with the error:

ERROR: Invalid property value '${gwt.user.agents}'

ERROR: Failure while parsing XML

How to place values from pom.xml to gwt.xml file via properties?

UPDATED

Interesting thing. When I use "mvn resources:resources", property's value writes correctly to gwt.xml file, but if I run "mvn clean install -pl com.myproject.module:submodule" it failes with "invalid property value".

Dragon
  • 2,431
  • 11
  • 42
  • 68

2 Answers2

3

You have to define a maven profile (better to define a specific profile for each cases) in your pom like this:

    <profile>
        <id>gecko</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <user.agent.gecko>
                <![CDATA[<set-property name="user.agent" value="gecko,gecko1_8" />]]>
            </user.agent.gecko>
        </properties>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*YourGWTModule.gwt.xml</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <defaultGoal>process-resources</defaultGoal>
        </build>
    </profile>

<properties>
    <!--<user.agent>ie6,ie8,gecko,gecko1_8,opera,safari</user.agent>-->
    <user.agent.all> </user.agent.all>
    <user.agent.ie6> </user.agent.ie6>
    <user.agent.ie8> </user.agent.ie8>
    <user.agent.gecko> </user.agent.gecko>
    <user.agent.opera> </user.agent.opera>
    <user.agent.safari> </user.agent.safari>
</properties>

Then set it in your YourGWTModule.gwt.xml like this:

<set-property name="locale" value="default" />
<!-- Specified through pom.xml profiles -->
${user.agent.all}
${user.agent.ie6}
${user.agent.ie8}
${user.agent.gecko}
${user.agent.safari}
${user.agent.opera}

</module>

Finally run maven with profile:

mvn -P gecko install
Saeed Zarinfam
  • 9,818
  • 7
  • 59
  • 72
  • 1
    But what if I have several modules that use GWT? I have to write (copy-paste) such profiles in each module pom.xml? I mean, if I want to build just one specific module using -pl option. I thought that placing property in the root pom.xml should be enough...with some addition configuration surely. – Dragon Jan 23 '13 at 20:15
  • @Dragon I think your solution is good or you can define a parent pom. – Saeed Zarinfam Jan 24 '13 at 10:15
  • Note (for future generations ;)): if you have a Spring Boot app you should use @....@ instead of ${...} as described here: https://stackoverflow.com/questions/36501017/maven-resource-filtering-not-working-because-of-spring-boot-dependency – machinery Jun 13 '17 at 10:24
0

There's one thing that I didn't mention but it appeared to be too important. Plugins that are used during build can have their own goals. And one of these goals can "redo" what maven-resource-plugin did.

So I had a plugin vaadin-maven-plugin:

<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<configuration>
    ...
</configuration>
<executions>
    <execution>
        <goals>
            <goal>resources</goal>
            <goal>compile</goal>
        </goals>
    </execution>
</executions>
</plugin>

And removal of a <goal>resources</goal> fixed the issue. And now mvn clean install filters properties in my gwt.xml correctly.

Hope this solution help those who will run at such an issue.

Dragon
  • 2,431
  • 11
  • 42
  • 68