{"id":15952615,"url":"https://github.com/skuzzle/semantic-version","last_synced_at":"2025-03-17T15:31:16.938Z","repository":{"id":18132106,"uuid":"21213142","full_name":"skuzzle/semantic-version","owner":"skuzzle","description":"Fast single-class semantic version implementation for java","archived":false,"fork":false,"pushed_at":"2022-05-23T07:13:03.000Z","size":249,"stargazers_count":43,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T00:53:27.456Z","etag":null,"topics":["java","sematinc-version","semver"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skuzzle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-25T18:05:09.000Z","updated_at":"2024-11-06T07:35:43.000Z","dependencies_parsed_at":"2022-07-25T06:32:01.336Z","dependency_job_id":null,"html_url":"https://github.com/skuzzle/semantic-version","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuzzle%2Fsemantic-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuzzle%2Fsemantic-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuzzle%2Fsemantic-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skuzzle%2Fsemantic-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skuzzle","download_url":"https://codeload.github.com/skuzzle/semantic-version/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243867323,"owners_count":20360743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","sematinc-version","semver"],"created_at":"2024-10-07T13:09:18.304Z","updated_at":"2025-03-17T15:31:16.615Z","avatar_url":"https://github.com/skuzzle.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/skuzzle/semantic-version.svg?branch=master)](https://travis-ci.org/skuzzle/semantic-version)\n[![Coverage Status](https://coveralls.io/repos/github/skuzzle/semantic-version/badge.svg?branch=master)](https://coveralls.io/github/skuzzle/semantic-version?branch=master)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.skuzzle/semantic-version/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.skuzzle/semantic-version)\n[![JavaDoc](http://javadoc-badge.appspot.com/de.skuzzle/semantic-version.svg?label=JavaDoc)](http://javadoc-badge.appspot.com/de.skuzzle/semantic-version)\n[![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS)\n\n\nsemantic-version\n================\n\nThis is a single-class [semantic version 2.0.0](http://semver.org/)\nimplementation for java 6+. It requires no further dependencies and is thereby\neasy to use within your own projects. Key features:\n\n* Lightweight: consists of only a single file, no dependencies\n* Immutable: strict immutability ensures easy handling and thread safety\n* Serializable: Objects can be serialized using Java's `ObjectOutputStream`.\n* Fast: Many performance improvements make this the fastest semver implementation in java\n  around (according to parsing and sorting performance)\n* Compatible: Supports Java 6 but also provides many methods that are suitable to be used \n  as method references in Java 8. Latest release also features a Java 9 module-info!\n* Stable: Ready for production since release 1.0.0 \n\n## Maven Dependency\nsemantic-version is available through the Maven Central Repository. Just add\nthe following dependency to your pom:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ede.skuzzle\u003c/groupId\u003e\n    \u003cartifactId\u003esemantic-version\u003c/artifactId\u003e\n    \u003cversion\u003e2.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Java 9\n\nReleases `\u003e=2.0.0` are bundled as a JPMS module. If you are using it in your Java 9 project,\nadd the following line to your `module-info.java`:\n\n```\nmodule com.your.module {\n    // ...\n    requires de.skuzzle.semantic;\n}\n```\n\n## Usage\n\n### Creation and parsing \n```java\n// Version with pre-release and build meta data field\nVersion v1 = Version.parseVersion(\"1.0.2-rc1.2+build-20142402\");\nVersion v2 = Version.create(1, 0 , 2, \"rc1.2\", \"build-20142402\");\n\n// Simple version\nVersion v3 = Version.parseVersion(\"1.0.2\");\nVersion v4 = Version.create(1, 0, 2);\n\n// Version with no pre-release field but with build meta data field\nVersion v5 = Version.parseVersion(\"1.0.2+build-20142402\");\nVersion v6 = Version.create(1, 0, 2, \"\", \"build-20142402\");\n\n```\n\n### Comparing\nVersions can be compared as they implement `Comparable`:\n\n```java\nif (v1.compareTo(v2) \u003c 0) { ... }\nif (v1.isGreaterThan(v2)) { ... }\nif (v1.isLowerThan(v2)) { ... }\n```\nIn rare cases it might be useful to compare versions with including the build meta data \nfield. If you need to do so, you can use\n\n```java\nv1.compareToWithBuildMetaData(v2)\nv1.equalsWithBuildMetaData(v2)\n```\n\nThere also exist static methods and comparators for comparing two versions.\n\n### Deriving\nYou can derive new versions from existing ones by modifying a single field:\n\n```java\nVersion v1 = Version.create(1, 0, 0)\n        .withMinor(2)\n        .withPatch(3)\n        .withPreRelease(\"alpha-1\")\n        .withBuildMetaData(\"build-20161022\");\n```\n\n### Incrementing\nVersions can also be incremented using any of the `next...` methods:\n\n```\n// Gives 2.0.0\nVersion.create(1, 2, 3).nextMajor();\n\n// Gives 1.3.0\nVersion.create(1, 2, 3).nextMinor();\n\n// Gives 1.2.4\nVersion.create(1, 2, 3).nextPatch();\n```\n\nAll `next...` methods will drop the pre-release and build meta data fields but provide an \noverload to set a new pre-release:\n\n```\n// Gives 2.0.0-SNAPSHOT\nVersion.create(1, 2, 3).nextMajor(\"SNAPSHOT\");\n```\n\nThe identifier parts can be incremented as well:\n\n```\n// Gives 1.2.3-1\nVersion.create(1, 2, 3).nextPreRelease();\n\n// Gives 1.2.3+1\nVersion.create(1, 2, 3).nextBuildMetaData();\n```\n\nIncrementing the identifier behaves as follows:\n* In case the identifier is currently empty, it becomes `1` in the result.\n* If the identifier's last part is numeric, that last part will be incremented in the result.\n* If the last part is not numeric, the identifier is interpreted as `identifier.0` which becomes `identifier.1` after increment.\n\nVersion | After increment\n--------| ---------------\n`1.2.3`| `1.2.3-1`\n`1.2.3+build.meta.data` | `1.2.3-1`\n`1.2.3-foo` | `1.2.3-foo.1`\n`1.2.3-foo.1` | `1.2.3-foo.2`\n\nThe special method `toStable` which has been introduced in version 2.1.0 will give give the next _stable_ version. \nThat is, it simply drops the pre-release and build meta data identifiers and leaves all other parts unmodified.\n\n### Serialization\nVersions can be written to/read from streams by Java's `ObjectOutputStream` and \n`ObjectInputStream` classes out of the box:\n\n```java \nnew ObjectOutputStream(yourOutStream).writeObject(Version.parseVersion(\"1.2.3\"));\nVersion version = (Version) new ObjectInputStream(yourInStream).readObject();\n```\n\nSerializing Versions from and to json is also possible but requires third party libraries\nlike `jackson` or `gson`. Support for those is not built in (in order to not ship extra \ndependencies) but examples can be found within the unit tests \n[here (jackson)](https://github.com/skuzzle/semantic-version/blob/master/src/test/java/de/skuzzle/semantic/CustomJacksonSerialization.java) \nand [here (gson)](https://github.com/skuzzle/semantic-version/blob/master/src/test/java/de/skuzzle/semantic/CustomGsonSerialization.java). Both examples will serialize the Version as its String representation as \nopposed to destructing it into its single fields.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskuzzle%2Fsemantic-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskuzzle%2Fsemantic-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskuzzle%2Fsemantic-version/lists"}