1

I'm new to Maven plugins, and I need to get this plugin working to run the sencha cmd tool to minify our JavaScript app as part of the daily build process.

Currently the executable tag has a hard coded path, but I'm wondering if I can specify the path as an environment variable, and then access that environment variable in the code below so it can be run on any machine?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>                    
    <executions>
        <execution>
            <id>sencha-compile</id>
            <phase>compile</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>C:\Sencha\Sencha\Cmd\4.0.2.67\sencha.exe</executable>
                <arguments>
                    <argument>app</argument>
                    <argument>build</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>            
Greg Lafrance
  • 809
  • 15
  • 35
  • What about [webminifier-maven-plugin](http://mojo.codehaus.org/webminifier-maven-plugin/)? Why using external program? – khmarbaise Feb 25 '14 at 16:36
  • Sencha Cmd tool resolves dependencies between the various JavaScript files in an ExtJS application. If these dependencies are not resolved, minification produces code that will not run. – Greg Lafrance Feb 25 '14 at 17:10

2 Answers2

1

Check my Sencha ExtJS 5 + Sencha Cmd 5 + Maven integration example at: https://github.com/dobromyslov/sencha-extjs-maven

You have to set environment variable:

  • Export it in console via:

    $ export SENCHA_CMD="/path/to/your/Sencha/Cmd/5.0.0.116/sencha"

  • Also you can add this export statement to your ~/.bashrc or /etc/profile file in order to make it permanent.

  • Or add new environment variable on Windows.

Set Sencha Cmd build environment:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- Default build environment -->
    <sencha.env>production</sencha.env>
</properties>

<profiles>
    <!-- Development profile -->
    <profile>
        <id>dev</id>
        <activation>
            <property>
                <name>env</name>
                <value>development</value>
            </property>
        </activation>
        <properties>
            <sencha.env>testing</sencha.env>
        </properties>
    </profile>

    <!-- Production profile -->
    <profile>
        <id>prod</id>
        <activation>
            <property>
                <name>env</name>
                <value>production</value>
            </property>
        </activation>
        <properties>
            <sencha.env>production</sencha.env>
        </properties>
    </profile>
</profiles>

Then use the following Maven plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>sencha-compile</id>
            <phase>compile</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <!-- Set path to your Sencha Cmd executable-->
                <executable>${env.SENCHA_CMD}</executable>
                <arguments>
                    <argument>-sdk</argument>
                    <argument>${basedir}/src/main/webapp</argument>
                    <argument>app</argument>
                    <argument>build</argument>
                    <argument>--clean</argument>
                    <argument>--environment</argument>
                    <argument>${sencha.env}</argument>
                    <argument>--destination</argument>
                    <argument>${basedir}/src/main/webapp/build</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

And run

$ mvn compile
Viacheslav Dobromyslov
  • 3,168
  • 1
  • 33
  • 45
0

To answer your question, you can reference system environment variables from within a maven pom file with this syntax: ${env.NAME_OF_VARIABLE}

See this link for more details: https://maven.apache.org/pom.html#Properties

If you named the environment variable PATH_TO_SENCHA_EXE you could reference it like this: <executable>${env.PATH_TO_SENCHA_EXE}sencha.exe</executable>

As an alternative to environment variables, you could consider creating a property in your pom to contain this path. Then you could change the value used for different environments by passing a new value for the property on the command line or by loading a properties file in your pom that may contain this property. There are many options here.

Edit: I found the latter suggestion has been covered on SO at the following link (and likely other places):

Reading properties file from Maven POM file

Community
  • 1
  • 1
ddanger
  • 101
  • 1
  • 4
  • I like your idea of creating a pom property for the path, and then setting the value on the command line. But I did not see reference to that technique in your link. – Greg Lafrance Feb 25 '14 at 17:29