This is a Kotlin project template that demonstrates how to build, test, and publish a Kotlin application using Gradle. It is configured to publish packages to GitHub Packages, and it includes CI/CD workflows using GitHub Actions.
- Kotlin Application Support: Set up for building a Kotlin application using Gradle.
- GitHub Packages Publishing: Configured to publish packages to GitHub Packages.
- Version Check on Publish: Automatically checks for existing versions before publishing.
- CI/CD with GitHub Actions: Includes workflows for building, testing, and publishing the application.
- Java Development Kit (JDK) 17 or later.
- Gradle (if not using the Gradle wrapper).
- A GitHub account with access to create repositories and GitHub Packages.
- Set up a GitHub Personal Access Token with the following scopes:
repo
: Full control of private repositories.write:packages
: Upload and publish packages to GitHub Packages.read:packages
: Download and install packages from GitHub Packages.delete:packages
(optional): Delete packages from GitHub Packages.
kotlin_template/
├── app/
│ ├── build.gradle.kts # Gradle build script for the application
│ ├── checkVersion.gradle.kts # Gradle script for checking version before publish
│ ├── projectConfig.build.kts # Additional project configurations
├── .github/
│ └── workflows/
│ ├── main.yml # GitHub Actions workflow for build and publication
│ └── test.yml # GitHub Actions workflow for testing
├── settings.gradle.kts # Gradle settings file (for multi-project builds)
└── README.md # Project documentation
-
Set up your Gradle environment: Ensure you have the necessary Gradle wrapper files to build the project.
-
Configure Project IDs: Set the
GROUP_ID
andARTIFACT_ID
in theprojectConfig.gradle.kts
file as follows:extra["GROUP_ID"] = "your.group.id" // e.g., com.example extra["ARTIFACT_ID"] = "your.artifact.id" // e.g., myapp
-
Set environment variables: The following environment variables need to be defined for successful publishing:
ORGANIZATION # GitHub organization or username GH_USERNAME # GitHub username GH_TOKEN # Personal access token for GitHub
-
Customize build.gradle.kts: Adjust the
mainClass
and dependencies according to your project needs.
To build the project, run:
./gradlew build
To execute the tests, run:
./gradlew test
Use the checkVersion
task to verify if the version exists before publication, then publish the package:
./gradlew publish
Two workflows are available in the .github/workflows/
directory:
-
Build and Publish Workflow (
main.yml
)- Manually triggered.
- Steps: Checkout code, set up Java (Temurin JDK 17), set up Gradle, build the package, tag the release, and publish to GitHub Packages.
-
Test Workflow (
test.yml
)- Automatically runs on pull requests and pushes to
develop
,master
, ormain
. - Steps: Checkout code, set up Java (Temurin JDK 17), set up Gradle, and run tests.
- Automatically runs on pull requests and pushes to
Feel free to submit issues and pull requests. Any contributions to enhance the template are welcome.
This software is published under the DO WHAT THE F*CK YOU WANT TO PUBLIC LICENSE license.