Publish to custom Maven repositories
In this tutorial, we will go through the process of publishing to a custom maven repository.
The sample project is here.
You need access to your own repository manager server. For learning purpose, you may setup a simple repository manager server on your local computer to try. There are a lot of open-source and commercial solutions for that, pick the one you like.
#
Project setup#
gradle.propertiesAdd maven server information to gradle.properties
. We can have multiple maven server settings in one gradle.properties
file. Each of the settings is identified by an ID. ("demo" in the example below.).
# ...repository.maven.demo.release=http://localhostrepository.maven.demo.snapshot=http://localhostrepository.maven.demo.username=writeuserrepository.maven.demo.password=....token....# The following line is needed only if release or snapshot URL are HTTP.repository.maven.demo.allowInsecureProtocol=true# ...
The last line is an opt-in step to allow the Jarbird plugin to use insecure server, to allow release and snapshot URL to be HTTP rather than HTTPS.
If you are using Rosilite server as the setup, fill in the
token for user writeuser
to ~/.gradle/gradle.properties
.
We need to provide a URL for the release version of the component, a URL for the snapshot version of the component, username and password of your account.
#
build.gradleTell Jarbird plugin that we want to publish to a custom Maven repository. We specify the ID of our Maven repository setting in gradle.properties
.
- build.gradle
- build.gradle.kts
// ...jarbird { pub { mavenRepo("demo") }}// ...
// ...jarbird { pub { mavenRepo("demo") }}// ...
The parameter of mavenRepo()
is the ID of the repository that we used to specify details in gradle.properties
#
pom.yamlUnlike MavenCentral, which need full POM information for proper publishing. We may skip some details in pom.xml for our custom repository. Jarbird gets all of those at the pom.yaml
file:
group: jarbirdsamplesartifactId: mevendemoversion: 1.0packaging: jar
licenses: - name: Apache-2.0 dist: repo
developers: - id: demo name: Jarbird Demo email: jarbird.demo@fake-email.com
scm: repoType: github.com repoName: demo/jarbird-samples/maven-demo
See reference for more details about the content of pom.yaml
.
Jarbird plugin read the file and create a proper POM file for publishing automatically.
With this setup, we can see more tasks available with ./gradlew tasks
Jarbird publishing tasks------------------------jbPublish - PublishjbPublishCustommaven - Publish module 'custommaven' to all targeted repositoriesjbPublishCustommavenToMavenDemo - Publish module 'custommaven' to Maven repository 'demo'jbPublishCustommavenToMavenLocal - Publish module 'custommaven' to Maven Local repositoryjbPublishCustommavenToMavenRepositories - Publish module 'custommaven' to all Maven repositoriesjbPublishToMavenDemo - Publish to Maven repository 'demo'jbPublishToMavenLocal - Publish to Maven Local repositoryjbPublishToMavenRepositories - Publish to all Maven repositories
The task jbPublish
publishes component to all specified repositories, which is MavenLocal and MavenCentral for this sample. We may use jbPublishToMavenDemo
to publish all of our components to the "demo" Maven repository.
If you are using the Rosilite server locally, you can observe the publishing activities at the console window of Rosilite, and find the published files at repositories
#
Appendix: Setup Reposilite serverReposilite is a simple, open-source Maven repository manager server. It can be set up in minutes on your local computer, which is ideal to learn about how Jarbird works with custom Maven repositories.
Assumed that you have an ordinary JDK (8+) installed on your computer.
#
Download the binaryDownload the jar here. At the time of writing, the latest version is 2.9.22. Create a directory locally, and place the jar file there.
#
Start serverStart the server with java -jar rosilite-2.9.22.jar
After it has finished starting up, we may type the command in the command shell window directly.
#
Create users and tokens- Type
keygen / adminuser m
, note the token generated. If you missed that, you may find it in the filetokens.dat
in the same directory. - Type
keygen / writeuser w
, note the token generated.