A plugin to build Flutter projects with Maven.
The plugin assumes the project follows the structure required by the Flutter SDK.
To make sure the project is configured as a Flutter package, make sure you define your packaging to match the plugin.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>YOUR PROJECT GROUP ID</groupId>
<artifactId>YOUR PROJECT ARTIFACT ID</artifactId>
<version>0.0.0-SNAPSHOT</version>
<packaging>flutter</packaging> :one:
<!-- ... -->
</project>
Currently, this plugin is only available via jitpack.io.
Add a reference to Jitpack in your project pom.xml
<project>
<!-- ... -->
<pluginRepositories>
<pluginRepository>
<id>jitpack</id>
<name>JitPack</name>
<url>https://jitpack.io</url> :two:
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- ... -->
</project>
To make sure Maven understands your Flutter project, define ${basedir}/build
as your project's
build directory.
<project>
<!-- ... -->
<build>
<directory>${project.basedir}/build</directory> :three:
<!-- ... -->
</build>
<!-- ... -->
</project>
Declare the flutter plugin. Make sure to include <extensions>true</extensions>
to allow the plugin
to configure tasks on the lifecycle.
<project>
<!-- ... -->
<build>
<!-- ... -->
<plugins>
<plugin>
<groupId>com.github.rivasdiaz</groupId>
<artifactId>flutter-maven-plugin</artifactId> :four:
<extensions>true</extensions>
<!-- flutter plugin configuration -->
</plugin>
<!-- ... -->
</plugins>
<!-- ... -->
</build>
<!-- ... -->
</project>
If you haven't created your Flutter project yet, you can create a basic project by running:
mvn flutter:create
This will create the project using the configuration defined on your POM. Make sure to include
the description tag as that's used to generate the pubspec.yaml
.
Add the parameter -Dflutter.target.platforms=<flutter platform list>
to generate scaffolding
for only a subset of the supported platforms, for example:
mvn flutter:create -Dflutter.target.platforms=web
To build your project, use the command:
mvn package
All supported platforms will be built. Use -Dflutter.target.<platform>.skip=true
to optionally
skip building some platforms.
To run your project, use the command:
mvn flutter:run -Dflutter.target.device=<device>
This command is not part of any maven lifecycle, and requires dependencies to be resolved. If you
have never build the project before, you can use flutter:dependencies
target.
For example, to run the web version of the app, use:
mvn flutter:dependencies flutter:run -Dflutter.target.device=chrome
You can check the list of available devices, by running:
mvn flutter:devices
clean
➡️flutter-maven-plugin:clean
initialize
➡️flutter-maven-plugin:dependencies
compile
➡️flutter-maven-plugin:build
test
➡️flutter-maven-plugin:test
Property | Default value | Description |
---|---|---|
flutterHomeDirectory |
${flutter.home} |
Optional. Define where is flutter installed. If not present, tries to run it from the path. |