Synchronizes the version of a package.json file with the version of the pom.xml.

Copyright © 2019-2021 The original authors.

Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.

1. Introduction

This Maven plugin allows you to synchronize the version of a package.json file with the version of the pom.xml.

2. Requirements

The following specifies the minimum requirements to run this Maven plugin:

Maven

3.3.9

JDK

1.8

Memory

Depends on your project.

Disk Space

No minimum requirement.

3. Usage

To synchronize the version of a package.json file with the version of the pom.xml you need to execute the sync goal manually.

$ mvn sync-packagejson-version:sync

To check if the version of a package.json file is in sync with the version of the pom.xml, include the appropriate XML in the plugins section of your pom.xml, as shown in the following example:

<project>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>some-artifact</artifactId>
    <!-- ... -->
    <build>
        <plugins>
            <plugin>
                <groupId>de.ingogriebsch.maven</groupId>
                <artifactId>sync-packagejson-version-maven-plugin</artifactId>
                <version>1.4.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <id>check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

If you want to use a snapshot release, you also need to add the appropriate pluginRepository elements, as shown in the following listing:

<project>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>some-artifact</artifactId>
    <!-- ... -->
    <pluginRepositories>
        <pluginRepository>
            <id>sonatype-snapshot-repository</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

The plugin offers a number of user properties, starting with sync-packagejson-version.<goal>.-, to let you customize the configuration from the command-line. For instance, you could prevent the build from failing even though no package.json file was found by running the following command:

$ mvn verify -Dsync-packagejson-version.check.failIfNoneFound=false

4. Goals

This plugin provides the following goals:

Goal Description

sync-packagejson-version:sync

Synchronizes the version of a package.json file with the version of the pom.xml.

sync-packagejson-version:check

Checks if a package.json file has the same version as the version declared in the pom.xml.

sync-packagejson-version:help

Display help information on the plugin. Call mvn sync-packagejson-version:help -Ddetail=true -Dgoal=<goal> to display parameter details.

4.1. sync

Synchronizes the version of a package.json file with the version of the pom.xml.

4.1.1. Attributes

  • Requires a Maven project to be executed.

  • Executes by direct invocation only.

4.1.2. Parameters

Parameter prefix is sync-packagejson-version.sync.

Name Type Description Mandatory Default User property

encoding

String

The encoding in which the package.json file is interpreted while executing this mojo.

false

${project.build.sourceEncoding}

encoding

includes

String[]

The list of files to include. Specified as file-set patterns which are relative to the projects root directory.

false

package.json,package-lock.json

includes

excludes

String[]

The list of files to exclude. Specified as file-set patterns which are relative to the projects root directory.

false

excludes

pomVersionEvaluation

String

The rule how the version of the pom.xml is evaluated. Permissible values are 'runtime' and 'static'.

false

runtime

pomVersionEvaluation

4.2. check

Checks if a package.json file has the same version as the version declared in the pom.xml.

4.2.1. Attributes

  • Requires a Maven project to be executed.

  • Binds to the verify lifecycle phase by default.

  • The goal is thread-safe and supports parallel builds.

4.2.2. Parameters

Parameter prefix is sync-packagejson-version.check.

Name Type Description Mandatory Default User property

skip

Boolean

Flag to control if the execution of the goal should be skipped.

false

false

skip

skipCheck

Boolean

Flag to control if the execution of the goal should be skipped. This parameter acts as an alias for parameter skip.

false

false

skipCheck

encoding

String

The encoding in which the package.json file is interpreted while executing this mojo.

false

${project.build.sourceEncoding}

encoding

includes

String[]

The list of files to include. Specified as file-set patterns which are relative to the projects root directory.

false

package.json,package-lock.json

includes

excludes

String[]

The list of files to exclude. Specified as file-set patterns which are relative to the projects root directory.

false

excludes

failIfNoneFound

Boolean

Flag to control if the execution of the goal should fail if no package.json is found.

false

true

failIfNoneFound

pomVersionEvaluation

String

The rule how the version of the pom.xml is evaluated. Permissible values are 'runtime' and 'static'.

false

runtime

pomVersionEvaluation

4.3. help

Display help information on the plugin. Call mvn sync-packagejson-version:help -Ddetail=true -Dgoal=<goal> to display parameter details.

4.3.1. Attributes

  • The goal is thread-safe and supports parallel builds.

4.3.2. Parameters

Parameter prefix is sync-packagejson-version.help.

Name Type Description Mandatory Default User property

detail

Boolean

If true, display all settable properties for each goal.

false

false

detail

goal

String

The name of the goal for which to show help. If unspecified, all goals will be displayed.

false

goal

indentSize

Number

The number of spaces per indentation level, should be positive.

false

2

indentSize

lineLength

Number

The maximum length of a display line, should be positive.

false

80

lineLength

5. Integration

5.1. Eclipse

This plugin contains support for M2E, including lifecycle mappings and support for incremental builds in Eclipse. The check goal support incremental builds to avoid doing unnecessary work.

License

This code is open source software licensed under the Apache 2.0 License.