Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:

Installation

Maven

Add the following dependency to your pom.xml:
<dependency>
    <groupId>com.scanoss</groupId>
    <artifactId>scanoss</artifactId>
    <version>0.13.0</version> <!-- Replace with the latest version available on Maven Central -->
</dependency>
A minimal pom.xml for a project using the SCANOSS SDK:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>scanoss-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.scanoss</groupId>
            <artifactId>scanoss</artifactId>
            <version>0.13.0</version> <!-- Replace with the latest version available on Maven Central -->
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <mainClass>com.example.YourMainClass</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
This configuration fetches the SCANOSS SDK and allows you to run your application using mvn exec:java. Replace com.example.YourMainClass with the fully qualified name of your entry point class.

Gradle

Add the following to your build.gradle dependencies block:
implementation group: 'com.scanoss', name: 'scanoss', version: '0.13.0'
Note: Ensure the version matches the Maven dependency above. Check Maven Central for the latest available release.

Default API Endpoint

By default, the Scanner class sends requests to the SCANOSS Open Source Software Knowledge Base (OSSKB) API at:
https://api.osskb.org
To use a different endpoint, configure the Scanner instance accordingly. Refer to the Configuration section for details.

Quick Start

To perform a scan using the default Scanner configuration:
import com.scanoss.Scanner;

public class Example {
    public static void main(String[] args) {
        Scanner scanner = Scanner.builder().build();
        String file = "test.java";
        String result = scanner.scanFile(file);
        System.out.println(result);
    }
}
Scanner.builder().build() constructs a Scanner instance using the default API endpoint and settings. The scanFile method returns the scan results as a JSON string.