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

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:
Download from gradle.org/releases
Extract the ZIP
Add
GRADLE_HOME/binto 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:
| Task | Description |
gradle clean | Cleans build directory |
gradle compileJava | Compiles Java source |
gradle test | Runs unit tests |
gradle build | Builds the project |
gradle run | Executes 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.0Upgrade:
pip install --upgrade flask
โ๏ธ PIP vs Poetry vs Conda
| Feature | PIP | Poetry | Conda |
| Virtual Env | โ | โ (auto) | โ |
| Dependency Resolution | Manual | Automatic | Automatic |
| Package Type | PyPI | PyPI | Python + Native libs |
| Best For | General Python | Modern packaging | Data 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
| Format | Language / Tool |
npm | Node.js |
Maven | Java |
Docker | Containers |
PyPI | Python |
NuGet | .NET |
๐ Publishing Packages to GitHub
Example: Python
Create
~/.pypirc:[distutils] index-servers = github [github] repository: https://upload.pypi.org/legacy/ username: __token__ password: YOUR_PERSONAL_ACCESS_TOKENUpload:
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.PATCHExample:
1.0.0โ Initial stable release1.1.0โ Added new feature1.1.1โ Bug fix
๐ Private vs Public Packages
| Type | Access | Use Case |
| Public | Open to everyone | Open-source libraries |
| Private | Limited to org/team | Internal 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
| Tool | Purpose | Key Use |
| Gradle | Build automation | Java, Python, C++ builds |
| PIP | Python package management | Install & publish packages |
| GitHub Packages | Artifact repository | Store 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.




