Hi everyone.
Ever since I started uploading projects on GitHub, I thought it was a bad idea that the source code of some libraries had to be copied into projects so they could be imported, or that the project had to be configured in NetBeans after being downloaded.
I learned nothing about build automation or dependency management in Computer Engineering, so I had no idea how to tackle this problem.
Then, last year, I started working with Maven. It's exactly what I always wanted. Only now I had the time to look into it further to see how I could publish my libraries in a Maven compatible way.
If you are just getting started with programming, here's a summary of how it works: you declare on a project that you need a library. Then, in order to build or run the project, Maven downloads the library, keeps it somewhere centralized, and links both together. This way, you don't need to deal with the library files manually, or change the project's settings whenever you place it in a different folder.
So, if you want to use my libraries but don't know Maven, fear not, you don't need to learn Maven. Just download the code, try to make it work, if it doesn't, search for and download the missing classes. But I highly suggest that you take a look into Maven. It makes so many things better, and it works in any IDE (that is compatible with Maven, but I suppose all the major ones are; I'm using Visual Studio Code now).
I looked into publishing my libraries to the Maven Central Repository but it was way too much work. Instead, I'm using JitPack to distribute my libraries straight from GitHub.
So, if you clone or download a project of mine, here's what you can do with it:
- Run it by using the Maven goal
exec:java
. - Build it by using the Maven goal
clean package
. If it's a project meant to be run standalone, it will generate an executablejar
file. If it depends on libraries, thejar
file will contain them too. - Include it in your Maven project by writing your
pom.xml
like this (this is not a workingpom.xml
, it just shows the relevant parts):<project> <repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.github.GuiRitter</groupId> <artifactId>RepositoryName</artifactId> <version>master-SNAPSHOT</version> </dependency> </dependencies> </project>
RepositoryName
can be obtained from the project's GitHub URL.