Build packages
Use the GitLab package registry to install and build packages for different package formats.
The following package managers are supported:
Composer
Create a directory called
my-composer-packageand change to that directory:mkdir my-composer-package && cd my-composer-packageRun
composer initand answer the prompts.For namespace, enter your unique namespace, like your GitLab username or group name.
A file called
composer.jsonis created:{ "name": "<namespace>/composer-test", "description": "Library XY", "type": "library", "license": "GPL-3.0-only", "authors": [ { "name": "John Doe", "email": "john@example.com" } ], "require": {} }
Conan 1
Install Conan 1
Prerequisites:
- You must install Conan version 1.x.
Download the Conan package manager to your local development environment by following the instructions at conan.io.
When installation is complete, verify you can use Conan in your terminal by running:
conan --versionThe Conan version is printed in the output:
Conan version 1.20.5Install CMake
When you develop with C++ and Conan, you can select from many available compilers. This example uses the CMake build system generator.
To install CMake:
- For Mac, use Homebrew and run
brew install cmake. - For other operating systems, follow the instructions at cmake.org.
When installation is complete, verify you can use CMake in your terminal by running:
cmake --versionThe CMake version is printed in the output.
Create a project
To test the package registry, you need a C++ project. If you don’t already have one, you can clone the Conan hello world starter project.
Build a Conan 1 package
To build a package:
Open a terminal and go to your project’s root folder.
Generate a new recipe by running
conan newwith a package name and version:conan new Hello/0.1 -tCreate a package for the recipe by running
conan createwith the Conan user and channel:conan create . mycompany/betaIf you use an instance remote, you must follow a specific naming convention.
A package with the recipe Hello/0.1@mycompany/beta is created.
For more details about creating and managing Conan packages, see the Conan documentation.
Conan 2
Install Conan 2
Prerequisites:
- You must install Conan version 2.x. Base Conan version 2 is available and future improvements can be tracked in epic 8258.
Install the Conan package manager to your local development environment by following the instructions at conan.io.
When you complete the installation, run the following command to verify you can use Conan in your terminal:
conan --versionThe Conan version is printed in the output:
Conan version 2.17.0Create Conan 2 profile
You must define a profile for Conan 2. If you already defined a profile, skip this step.
To create a profile, run the following command:
conan profile detectCheck the profile:
conan profile listThe command lists the profile in the output:
Profiles found in the cache:
defaultThe generated profile is usually enough to get started. For more information on Conan profiles, see Conan 2 profiles.
Install CMake
When you develop with C++ and Conan, you can select from many available compilers. The following example uses the CMake build system generator.
Prerequisites:
- Install CMake.
When installation is complete, verify you can use CMake in your terminal with the following command:
cmake --versionThe CMake version is printed in the output.
Create a project
Prerequisites:
- To test the package registry, you must have a C++ project.
Go to your local project folder and use the conan new command to create a “Hello World” C++ library example project with the cmake_lib template:
mkdir hello && cd hello
conan new cmake_lib -d name=hello -d version=0.1For more advanced examples, see the Conan 2 examples project.
Build a Conan 2 package
Prerequisites:
To build a package:
Make sure you are in the
hellofolder created in the previous section.Create a package for the recipe by running
conan createwith the Conan user and channel:conan create . --channel=beta --user=mycompany
A package with the recipe hello/0.1@mycompany/beta is created.
For more details about creating and managing Conan packages, see Creating packages.
Maven
Install Maven
The required minimum versions are:
- Java 11.0.5+
- Maven 3.6+
Follow the instructions at maven.apache.org to download and install Maven for your local development environment. After installation is complete, verify you can use Maven in your terminal by running:
mvn --versionThe output should be similar to:
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T20:00:29+01:00)
Maven home: /Users/<your_user>/apache-maven-3.6.1
Java version: 12.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.2", arch: "x86_64", family: "mac"Build a Maven package
Open your terminal and create a directory to store the project.
From the new directory, run this Maven command to initialize a new package:
mvn archetype:generate -DgroupId=com.mycompany.mydepartment -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=falseThe arguments are:
DgroupId: A unique string that identifies your package. Follow the Maven naming conventions.DartifactId: The name of theJAR, appended to the end of theDgroupId.DarchetypeArtifactId: The archetype used to create the initial structure of the project.DinteractiveMode: Create the project using batch mode (optional).
This message indicates that the project was set up successfully:
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.429 s
[INFO] Finished at: 2020-01-28T11:47:04Z
[INFO] ------------------------------------------------------------------------In the folder where you ran the command, a new directory should be displayed.
The directory name should match the DartifactId parameter, which in this case,
is my-project.
Gradle
Install Gradle
If you want to create a new Gradle project, you must install Gradle. Follow instructions at gradle.org to download and install Gradle for your local development environment.
In your terminal, verify you can use Gradle by running:
gradle -versionTo use an existing Gradle project, in the project directory,
on Linux execute gradlew, or on Windows execute gradlew.bat.
The output should be similar to:
------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------
Build time: 2019-11-18 20:25:01 UTC
Revision: fad121066a68c4701acd362daf4287a7c309a0f5
Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.5 (Oracle Corporation 11.0.5+10)
OS: Windows 10 10.0 amd64Create a package
Open your terminal and create a directory to store the project.
From this new directory, run this command to initialize a new package:
gradle initThe output should be:
Select type of project to generate: 1: basic 2: application 3: library 4: Gradle plugin Enter selection (default: basic) [1..4]Enter
3to create a new Library project. The output should be:Select implementation language: 1: C++ 2: Groovy 3: Java 4: Kotlin 5: Scala 6: SwiftEnter
3to create a new Java Library project. The output should be:Select build script DSL: 1: Groovy 2: Kotlin Enter selection (default: Groovy) [1..2]Enter
1to create a new Java Library project that is described in Groovy DSL, or2to create one that is described in Kotlin DSL. The output should be:Select test framework: 1: JUnit 4 2: TestNG 3: Spock 4: JUnit JupiterEnter
1to initialize the project with JUnit 4 testing libraries. The output should be:Project name (default: test):Enter a project name or press Enter to use the directory name as project name.
sbt
Install sbt
Install sbt to create new sbt projects.
To install sbt for your development environment:
Follow the instructions at scala-sbt.org.
From your terminal, verify you can use sbt:
sbt --version
The output is similar to:
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)
sbt script version: 1.9.8Create a Scala project
Open your terminal and create a directory to store the project.
From the new directory, initialize a new project:
sbt new scala/scala-seed.g8The output is:
Minimum Scala build. name [My Something Project]: hello Template applied in ./helloEnter a project name or press Enter to use the directory name as project name.
Open the
build.sbtfile and edit it as described in the sbt documentation to publish your project to the package registry.
npm
Install npm
Install Node.js and npm in your local development environment by following the instructions at npmjs.com.
When installation is complete, verify you can use npm in your terminal by running:
npm --versionThe npm version is shown in the output:
6.10.3Create an npm package
Create an empty directory.
Go to the directory and initialize an empty package by running:
npm initEnter responses to the questions. Ensure the package name follows the naming convention and is scoped to the project or group where the registry exists.
Yarn
Install Yarn
As an alternative to npm, you can install Yarn in your local environment by following the instructions at classic.yarnpkg.com.
When installation is complete, verify you can use Yarn in your terminal by running:
yarn --versionThe Yarn version is shown in the output:
1.19.1Create a package
Create an empty directory.
Go to the directory and initialize an empty package by running:
yarn initEnter responses to the questions. Ensure the package name follows the naming convention and is scoped to the project or group where the registry exists.
A package.json file is created.
NuGet
Install NuGet
Follow the instructions from Microsoft to install NuGet. If you have Visual Studio, NuGet is probably already installed.
Verify that the NuGet CLI is installed by running:
nuget helpThe output should be similar to:
NuGet Version: 5.1.0.6013
usage: NuGet <command> [args] [options]
Type 'NuGet help <command>' for help on a specific command.
Available commands:
[output truncated]PyPI
Install pip and twine
Install a recent version of pip and twine.
Create a project
Create a test project.
Open your terminal.
Create a directory called
MyPyPiPackage, and then go to that directory:mkdir MyPyPiPackage && cd MyPyPiPackageCreate another directory and go to it:
mkdir mypypipackage && cd mypypipackageCreate the required files in this directory:
touch __init__.py touch greet.pyOpen the
greet.pyfile, and then add:def SayHello(): print("Hello from MyPyPiPackage") returnOpen the
__init__.pyfile, and then add:from .greet import SayHelloTo test the code, in your
MyPyPiPackagedirectory, start the Python prompt.pythonRun this command:
>>> from mypypipackage import SayHello >>> SayHello()
A message indicates that the project was set up successfully:
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from mypypipackage import SayHello
>>> SayHello()
Hello from MyPyPiPackageCreate a PyPI package
After you create a project, you can create a package.
In your terminal, go to the
MyPyPiPackagedirectory.Create a
pyproject.tomlfile:touch pyproject.tomlThis file contains all the information about the package. For more information about this file, see creating
pyproject.toml. Because GitLab identifies packages based on Python normalized names (PEP-503), ensure your package name meets these requirements. See the installation section for details.Open the
pyproject.tomlfile, and then add basic information:[build-system] requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] name = "mypypipackage" version = "0.0.1" authors = [ { name="Example Author", email="author@example.com" }, ] description = "A small example package" requires-python = ">=3.7" classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent", ] [tool.setuptools.packages] find = {}Save the file.
Install the package build library:
pip install buildBuild the package:
python -m build
The output should be visible in a newly-created dist folder:
ls distThe output should appear similar to the following:
mypypipackage-0.0.1-py3-none-any.whl mypypipackage-0.0.1.tar.gzThe package is now ready to be published to the package registry.