Skip to main content

Command Palette

Search for a command to run...

๐Ÿงฑ Mastering Gradle, PIP, and GitHub Packages โ€” The Complete Build, Dependency, and Publishing Guide

Published
โ€ข6 min read
๐Ÿงฑ Mastering Gradle, PIP, and GitHub Packages โ€” The Complete Build, Dependency, and Publishing Guide
B

I am Bittu Sharma, a DevOps & AI Engineer with a keen interest in building intelligent, automated systems. My goal is to bridge the gap between software engineering and data science, ensuring scalable deployments and efficient model operations in production.! ๐—Ÿ๐—ฒ๐˜'๐˜€ ๐—–๐—ผ๐—ป๐—ป๐—ฒ๐—ฐ๐˜ I would love the opportunity to connect and contribute. Feel free to DM me on LinkedIn itself or reach out to me at bittush9534@gmail.com. I look forward to connecting and networking with people in this exciting Tech World.

๐Ÿš€ Introduction

Modern software development isnโ€™t just about writing code โ€” itโ€™s about building, packaging, and managing dependencies efficiently.

This guide will help you understand three essential tools:

  • Gradle โ€” A powerful build automation tool for Java, C++, and Python.

  • PIP โ€” The default package manager for Python.

  • GitHub Packages โ€” GitHubโ€™s secure package registry for sharing artifacts and managing dependencies.

By the end, youโ€™ll understand how to automate builds, manage dependencies, and publish your own packages with ease.


๐Ÿงฉ Part 1: Gradle โ€” The Build Automation Powerhouse


โš™๏ธ What is Gradle?

Gradle is a flexible build automation tool that supports multiple languages like Java, Kotlin, C++, and Python.
It uses a Groovy or Kotlin DSL to define how projects are built, tested, and packaged.

It combines the best features of Ant and Maven, with faster builds through incremental compilation and build caching.


๐Ÿ’ป Installing and Configuring Gradle

๐Ÿ”น Installation Steps

Windows / macOS / Linux (via SDKMAN):

sdk install gradle

Or manually:

  1. Download from gradle.org/releases

  2. Extract the ZIP

  3. Add GRADLE_HOME/bin to your PATH

Verify Installation

gradle -v

๐Ÿ—๏ธ Gradle Project Structure

A simple Java project structure looks like this:

my-gradle-project/
โ”‚
โ”œโ”€โ”€ build.gradle
โ”œโ”€โ”€ settings.gradle
โ”œโ”€โ”€ gradle/
โ”‚   โ””โ”€โ”€ wrapper/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/java/
โ”‚   โ””โ”€โ”€ test/java/
โ””โ”€โ”€ build/

โš’๏ธ Building Java and C++ Projects

๐Ÿ”น Java Example

build.gradle

plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'junit:junit:4.13.2'
}

Run Build:

gradle build

๐Ÿ”น C++ Example

build.gradle

plugins {
    id 'cpp-application'
}

application {
    targetMachines.add(machines.linux.x86_64)
}

Build Command:

gradle build

๐Ÿ Build Python Project with Gradle Plugins

Use PyGradle plugin for integrating Python.

plugins {
    id 'com.linkedin.python' version '0.9.8'
}

python {
    details.pythonVersion = '3.10'
}

Run:

gradle build

๐Ÿ“ฆ Dependency Management

Gradle manages dependencies through repositories like:

  • Maven Central

  • Google

  • JCenter (deprecated)

  • Local repositories

You can view dependencies:

gradle dependencies

๐Ÿ” Gradle Tasks and Lifecycle

Common tasks:

TaskDescription
gradle cleanCleans build directory
gradle compileJavaCompiles Java source
gradle testRuns unit tests
gradle buildBuilds the project
gradle runExecutes the application

View all tasks:

gradle tasks

โšก Custom Build Scripts

You can define custom tasks in build.gradle:

task hello {
    doLast {
        println 'Hello from Gradle!'
    }
}

Run it:

gradle hello

๐Ÿงฉ Using Gradle Plugins

Gradle plugins extend functionality. Examples include:

  • Java Plugin

  • Application Plugin

  • Docker Plugin

  • Spring Boot Plugin

Example:

plugins {
    id 'application'
}

โš™๏ธ Gradle Properties and Profiles

Define environment variables in gradle.properties:

app.env=dev
app.version=1.0.0

Access them in your build script:

println project.property("app.env")

๐Ÿงฉ Part 2: PIP โ€” Python Package Manager


๐Ÿ What is PIP?

PIP (Pip Installs Packages) is Pythonโ€™s official package manager.
It allows you to install, update, and manage third-party libraries from PyPI.


๐Ÿ’พ Installing Python Packages

pip install requests

List installed packages:

pip list

๐Ÿ“œ Understanding requirements.txt

The requirements.txt file contains all dependencies for a project.

Example:

Flask==3.0.0
SQLAlchemy==2.0.10
requests>=2.31.0

Install from it:

pip install -r requirements.txt

๐ŸŒ Creating Virtual Environments

Virtual environments isolate dependencies.

python -m venv venv
source venv/bin/activate     # Linux/macOS
venv\Scripts\activate        # Windows

Deactivate:

deactivate

๐Ÿ” Using pip freeze and pip list

List all dependencies with exact versions:

pip freeze > requirements.txt

๐Ÿš€ Publishing Python Packages

Step 1: Create setup.py

from setuptools import setup

setup(
    name='my_package',
    version='0.1.0',
    packages=['my_package'],
    install_requires=['requests']
)

Step 2: Build Package

python setup.py sdist bdist_wheel

Step 3: Upload to PyPI

pip install twine
twine upload dist/*

๐Ÿ“˜ Using pyproject.toml

Modern projects use pyproject.toml:

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "my_package"
version = "0.1.0"
dependencies = ["requests"]

๐Ÿ”— Installing from Git or Local Source

pip install git+https://github.com/user/repo.git
pip install ./local-package/

๐Ÿงฎ Managing Package Versions

  • Install specific version:

      pip install flask==3.0.0
    
  • Upgrade:

      pip install --upgrade flask
    

โš–๏ธ PIP vs Poetry vs Conda

FeaturePIPPoetryConda
Virtual Envโœ…โœ… (auto)โœ…
Dependency ResolutionManualAutomaticAutomatic
Package TypePyPIPyPIPython + Native libs
Best ForGeneral PythonModern packagingData Science

๐Ÿงฉ Part 3: GitHub Packages โ€” Managing and Publishing Artifacts


๐Ÿ—‚๏ธ What is GitHub Packages?

GitHub Packages is a secure artifact management service that integrates directly with your repositories.
It supports npm, Maven, Docker, PyPI, and NuGet packages.


๐Ÿ“ฆ Supported Formats

FormatLanguage / Tool
npmNode.js
MavenJava
DockerContainers
PyPIPython
NuGet.NET

๐Ÿš€ Publishing Packages to GitHub

Example: Python

  1. Create ~/.pypirc:

     [distutils]
     index-servers =
         github
    
     [github]
     repository: https://upload.pypi.org/legacy/
     username: __token__
     password: YOUR_PERSONAL_ACCESS_TOKEN
    
  2. Upload:

     twine upload --repository github dist/*
    

๐Ÿ”‘ Authenticating with Personal Access Tokens (PAT)

Generate a PAT from GitHub โ†’ Settings โ†’ Developer Settings โ†’ Tokens with write:packages and read:packages scopes.

Set it as an environment variable:

export CR_PAT=your_token
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

โš™๏ธ Installing Packages via GitHub Registry

Python Example:

pip install --extra-index-url https://pypi.github.com/username/ my_package

๐Ÿ” Using GitHub Actions for CI/CD Publishing

Example Workflow: .github/workflows/publish.yml

name: Publish Python Package

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'
      - run: pip install build twine
      - run: python -m build
      - name: Publish to GitHub Packages
        run: twine upload --repository github dist/*
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

๐Ÿ”ข Managing Package Versions

  • Use semantic versioning (SemVer): MAJOR.MINOR.PATCH

  • Example:

    • 1.0.0 โ†’ Initial stable release

    • 1.1.0 โ†’ Added new feature

    • 1.1.1 โ†’ Bug fix


๐Ÿ” Private vs Public Packages

TypeAccessUse Case
PublicOpen to everyoneOpen-source libraries
PrivateLimited to org/teamInternal services

๐Ÿ›ก๏ธ Security & Access Control

  • Enable Dependabot to monitor vulnerabilities.

  • Use Role-based Access for private packages.

  • Rotate access tokens regularly.


๐Ÿงฑ GitHub Packages with SBOM & Dependabot

SBOM (Software Bill of Materials) ensures supply chain transparency.
Enable in repository settings โ†’ Security โ†’ Supply chain.

Dependabot Alerts notify you of outdated or vulnerable dependencies and can automatically open PRs to fix them.


๐Ÿงญ Summary

ToolPurposeKey Use
GradleBuild automationJava, Python, C++ builds
PIPPython package managementInstall & publish packages
GitHub PackagesArtifact repositoryStore and distribute builds

๐Ÿ Conclusion

From building software (Gradle) to managing dependencies (PIP) and publishing artifacts (GitHub Packages) โ€” this blog covered the complete ecosystem of modern software delivery.

By mastering these tools, youโ€™ll streamline builds, ensure version consistency, and simplify CI/CD workflows for professional-grade software projects.

More from this blog