How to build dart project with dart-maven-plugin?

2019-07-21 03:40发布

问题:

I need to build my Dart project with Maven.

I've found dart-maven-plugin for this goal, and it works fine for resolving dependencies.

In Dart I compile my project with two commands:

  1. pub get

  2. pub build

So, when I write

mvn dart:pub

it gets all dependencies.

Now I need to build my project. So, I write

mvn dart:pub -DpubCommand=build

but it's still resolving dependencies, it doesn't build the project!

How can I build project with dart-maven-plugin?

回答1:

I've wrote wrong parameter name. Correctly will be:

    mvn dart:pub -Ddart.pub.command=build

Also there is example project name - "dart-maven-plugin-example"
Don't build this project, it will not build cause there is no web folder in some sub-projects.
Hope it will help some one else.



回答2:

If you want to do this you can just add this ant plugin to your project:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>compile</phase>
            <configuration>
                <tasks>
                    <exec executable="cmd" osfamily="windows" dir="${project.basedir}/src/main/dart/home">
                        <arg value="/c"/>
                        <arg value="pub.bat"/>
                        <arg value="build"/>
                    </exec>
                    <exec executable="/bin/sh" osfamily="mac" dir="${project.basedir}/src/main/dart/pegboard">
                        <arg value="-c"/>
                        <arg value="pub build --mode=debug"/>
                    </exec>
                    <copy todir="${project.build.directory}/classes/static">
                        <fileset dir="${project.basedir}/src/main/dart/your-dart-project-name/build/web">
                            <include name="*/**"/>
                        </fileset>
                    </copy>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

These two ant tasks will run 'pub build' and then copy your build files to the approriate directory. This here is set up for a spring boot app that is serving files from the static folder. You can change the locations of the files. Replace the 'your-dart-project-name' with your dart project name. The '*/**' is an ant matcher that will match all files recursively.

The exec command requires that you have added your dart-sdk 'bin' folder to your classpath. That will let pub be executable.