Snyk Maven CLI Plugin

4.6.1 · active · verified Wed Apr 22

The `snyk-mvn-plugin` is an internal JavaScript/TypeScript component primarily designed to be used by the Snyk CLI tool. Its core function is to analyze Maven project dependencies by inspecting `pom.xml` files and archive files (like JAR/WAR) to build detailed dependency graphs. It supports optional inclusion of test-scoped dependencies, provides verbose output for comprehensive version resolution, and can generate cryptographic artifact fingerprints for supply chain integrity. The current stable version is 4.6.1, released on 2026-03-23, with a frequent release cadence indicating active development and continuous feature enhancements and bug fixes. This plugin is distinct from the `snyk-maven-plugin`, which is a native Maven plugin for integrating Snyk tasks directly into a Maven build process. This package specifically focuses on providing dependency metadata to the Snyk CLI for vulnerability scanning and requires Node.js 20 or higher for execution.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use the `inspect` function to analyze a Maven `pom.xml` file, including options for provenance and algorithm selection.

import { inspect } from 'snyk-mvn-plugin';
import * as path from 'path';
import * as fs from 'fs';

async function runSnykMavenInspection() {
  const projectRoot = process.cwd(); // Assume running from project root
  const targetPom = path.join(projectRoot, 'pom.xml');

  if (!fs.existsSync(targetPom)) {
    console.error(`Error: pom.xml not found at ${targetPom}`);
    console.error('Please ensure you run this from a Maven project root or specify targetFile.');
    process.exit(1);
  }

  console.log(`Inspecting Maven project at: ${projectRoot}`);
  console.log(`Using target file: ${targetPom}`);

  try {
    const options = {
      dev: false, // Do not include development dependencies
      includeProvenance: true, // Generate cryptographic fingerprints for artifacts
      fingerprintAlgorithm: 'sha256', // Use SHA-256 for fingerprinting
      // mavenRepository: '/path/to/custom/repo' // Uncomment and adjust if you have a custom local Maven repository
    };

    const result = await inspect(projectRoot, targetPom, options);

    console.log('Inspection complete.');
    console.log(`Found ${result.pkgs ? result.pkgs.length : 0} packages.`);
    if (result.pkgs && result.pkgs.length > 0 && result.pkgs[0].info.purl) {
      console.log('First package PURL with checksum:', result.pkgs[0].info.purl);
    }
    // Uncomment the line below for full JSON output
    // console.log(JSON.stringify(result, null, 2));
  } catch (error: any) {
    console.error('Error during inspection:', error.message);
    process.exit(1);
  }
}

runSnykMavenInspection();

view raw JSON →