Skip to main content

Working with Maven

Publish Maven Package

  1. Use below repositories in project pom.xml:

    <repositories>
    <repository>
    <id>onedev</id>
    <url>https://onedev.example.com/<project path>/~maven</url>
    </repository>
    </repositories>
    <distributionManagement>
    <repository>
    <id>onedev</id>
    <url>https://onedev.example.com/<project path>/~maven</url>
    </repository>
    <snapshotRepository>
    <id>onedev</id>
    <url>https://onedev.example.com/<project path>/~maven</url>
    </snapshotRepository>
    </distributionManagement>
    ParamExplanation
    <project path>path of a project with package management enabled
  2. Add below to $HOME/.m2/settings.xml if you want to deploy from command line:

    <servers>
    <server>
    <id>onedev</id>
    <!-- Make sure the account has package write permission over the project -->
    <username>onedev_account_name</username>
    <password>onedev_password_or_access_token</password>
    </server>
    </servers>
  3. For CI/CD job, it is more convenient to use a custom settings.xml, for instance via below code in a command step:

    cat << EOF > settings.xml
    <settings>
    <servers>
    <server>
    <id>onedev</id>
    <!-- Use job token as user name so that OneDev can know which build is deploying packages -->
    <username>@job_token@</username>
    <!-- Job secret 'access-token' should be defined in project build setting as an access token with package write permission -->
    <password>@secret:access-token@</password>
    </server>
    </servers>
    </settings>
    EOF

    mvn --settings settings.xml clean deploy

Consume Published Maven Package

The package detail page contains instructions on how to consume published image.

Query Published Maven Package

When query maven package from package list page, Name should be specified in form of <group id>:<artifact id>. Wildcard can be used for name query, for instance io.onedev.server:* will match all packages with group id io.onedev.server