Skip to content

Commit

Permalink
Merge pull request #19 from mainmethod0126/16-we-need-to-develop-a-fe…
Browse files Browse the repository at this point in the history
…ature-that-allows-optional-selection-for-whether-the-directory-should-be-created-based-on-the-build-date-or-not

16 we need to develop a feature that allows optional selection for whether the directory should be created based on the build date or not
  • Loading branch information
mainmethod0126 authored Oct 21, 2023
2 parents 1415d12 + d6ad5f2 commit 7ea9906
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 51 deletions.
24 changes: 20 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic",
"java.dependency.syncWithFolderExplorer": true
}
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic",
"java.dependency.syncWithFolderExplorer": true,
"java.jdt.ls.java.home": "C:\\Program Files\\Zulu\\zulu-11",
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "C:\\Program Files\\Zulu\\zulu-8"
},
{
"name": "JavaSE-11",
"path": "C:\\Program Files\\Zulu\\zulu-11",
"default": true
},
{
"name": "JavaSE-17",
"path": "C:\\Program Files\\Zulu\\zulu-17"
}
]
}
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# simple-semantic-version
![GitHub](https://img.shields.io/github/license/mainmethod0126/simple-semantic-version?style=plastic) [![Build Verification](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/build-verification.yml/badge.svg)](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/build-verification.yml) [![Gradle Package](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/gradle-publish.yml/badge.svg)](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/gradle-publish.yml)


![GitHub](https://img.shields.io/github/license/mainmethod0126/simple-semantic-version?style=plastic) [![Build Verification](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/build-verification.yml/badge.svg)](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/build-verification.yml) [![Gradle Package](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/gradle-publish.yml/badge.svg)](https://github.com/mainmethod0126/simple-semantic-version/actions/workflows/gradle-publish.yml)

This is a gradle plugin that helps you easily do semantic versioning of java projects using gradle.

Expand All @@ -18,6 +17,7 @@ To address this, I decided to create a versioning library for .jar files that wo
## Setting build.gradle

### from Local File

```gradle
buildscript {
dependencies {
Expand All @@ -31,11 +31,13 @@ plugins {
apply plugin: 'io.github.mainmethod0126.simple-semantic-version'
```

### from Gradle Plugin Portal

https://plugins.gradle.org/plugin/io.github.mainmethod0126.simple-semantic-version

#### Using legacy plugin application:

```gradle
buildscript {
repositories {
Expand All @@ -51,96 +53,127 @@ buildscript {
apply plugin: "io.github.mainmethod0126.simple-semantic-version"
```

#### Using the plugins DSL:
**Currently, the "Using the plugins DSL" method is not available. We will try to solve the problem as soon as possible.**
#### Using the plugins DSL:

**Currently, the "Using the plugins DSL" method is not available. We will try to solve the problem as soon as possible.**

## Example

### Version Increment

#### Major

```bash
gradlew build -Pmajor=++
```

#### Minor

```bash
gradlew build -Pminor=++
```

#### Patch

```bash
gradlew build -Ppatch=++
```

#### Prerelease(pr)

PrereleaseVersion Since version is in text format, incremental method is not supported.

#### BuildMetadata(bm)

BuildMetadataVersion Since version is in text format, incremental method is not supported.

### Version Change

#### Major

```bash
gradlew build -Pmajor=1
```

#### Minor

```bash
gradlew build -Pminor=2
```

#### Patch

```bash
gradlew build -Ppatch=3
```

#### Prerelease(pr)

```bash
gradlew build -Ppr=beta
```

#### BuildMetadata(bm)

```bash
gradlew build -Pbm=test
```

#### Java Version

```bash
gradlew build -Pjavav=17
```


#### Compositive

```bash
gradlew build -Pmajor=1 -Pminor=2 -Ppatch=3 -Ppr=beta -Pbm=test -Pjavav=17
```

### Properties

```groovy
ssv {
buildDate = "2023-10-21";
isDateInBuildArtifactDirPath = true;
applicationVersion = "0.0.0";
}
```

| Property name | Description | Default |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ssv.buildDate` | This is the build date. | today |
| `ssv.isDateInBuildArtifactDirPath` | Indicates whether `buildDate` should be included in `BuildArtifactDirPath`. If `true`, a directory is created with the name `buildDate`. If `false`, no directory is created. | `false` |
| `ssv.applicationVersion` | This is the application version. | The content of the `version.json` file if the `version.json` file exists. If the `version.json` file does not exist, the default value is "0.0.0". |

---

## Build Artifacts Sample

```bash
gradlew build -Pmajor=1 -Pminor=2 -Ppatch=3 -Ppr=beta -Pbm=test -Pjavav=17
```

```bash
<application root>/dist/<YYYY-MM-DD>/<java version>/<version>/app-<major.minor.patch>-<prereleaseVersion>-<buildMetadata>.jar
```

![gradle-build-sample](https://user-images.githubusercontent.com/40654598/217150085-e10d11ff-e9c4-45a2-ad3e-ba9d1746c93f.PNG)
![gradle-build-sample2](https://user-images.githubusercontent.com/40654598/217150322-fdf25a72-c884-4bdc-b61b-c0ed2e961c5d.PNG)


### Directory : dist

A folder called "dist" is automatically created in the application root path, and Build Artifacts are located under the "dist" folder. (If it already exists, the creation process is skipped)

### Directory : YYYY-MM-DD

The year, month, and day information of the build is created as a directory. (ex: 2023-02-07)

### Directory : java version

During gradle build, the java version entered through -Pjavav is created as a directory. (When the javav option is omitted, the build java version is used by default)

### Directory : version
The directory is created with the final version information generated during Gradle build. (ex : app-1.2.3-beta-test)

The directory is created with the final version information generated during Gradle build. (ex : app-1.2.3-beta-test)
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ apply plugin: 'com.github.johnrengelman.shadow'


group = 'io.github.mainmethod0126'
version = "0.1.1"
version = "0.1.2"
sourceCompatibility = 11
targetCompatibility = 11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
import org.gradle.api.initialization.Settings;
import org.gradle.api.invocation.Gradle;

import io.github.mainmethod0126.gradle.simple.versioning.extension.SimpleSemanticVersionPluginExtension;
import io.github.mainmethod0126.gradle.simple.versioning.task.BuildAndVersioning;
import io.github.mainmethod0126.gradle.simple.versioning.utils.SsvPaths;

public class SemanticVersionManager implements Plugin<Project> {

private Project project;

@Override
public void apply(Project project) {

this.project = project;

initExtensions();
initUtils();

BuildAndVersioning buildAndVersioning = project.getTasks().create("BuildAndVersioning",
BuildAndVersioning.class);

Expand Down Expand Up @@ -78,4 +87,12 @@ public void settingsEvaluated(Settings buildResult) {

}

private void initExtensions() {
SimpleSemanticVersionPluginExtension.init(this.project);
}

private void initUtils() {
SsvPaths.init(this.project);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.github.mainmethod0126.gradle.simple.versioning.extension;

import org.gradle.api.Project;

import io.github.mainmethod0126.gradle.simple.versioning.utils.DateUtils;

/**
*
* I wanted to create it as a singleton object, but it seemed like we would
* always have to pass the 'project' object as an argument when calling
* {@code getInstance()} from outside. Therefore, I created the object to be
* conveniently used after calling the initial {@code initExtension()} function.
*
* warn! : This class was not designed with consideration for multi-threading
* and is not thread-safe. Please be cautious when using it in a multi-threaded
* environment.
*/
public class SimpleSemanticVersionPluginExtension {

/**
* This is not a singleton object, but rather a global variable used for the
* convenience of users.
*/
private static SimpleSemanticVersionPluginExtension extension;

public static void init(Project project) {
if (extension == null) {
extension = project.getExtensions().create("ssv",
SimpleSemanticVersionPluginExtension.class);
}
}

public static SimpleSemanticVersionPluginExtension getExtension() {
return extension;
}

private String buildDate = DateUtils.getCurrentDate(DateUtils.DateUnit.DAY);
private boolean isDateInBuildArtifactDirPath = false;
private String applicationVersion = "0.0.0";

public boolean isDateInBuildArtifactDirPath() {
return isDateInBuildArtifactDirPath;
}

public void setDateInBuildPath(boolean isDateInBuildArtifactDirPath) {
this.isDateInBuildArtifactDirPath = isDateInBuildArtifactDirPath;
}

public String getBuildDate() {
return buildDate;
}

public void setBuildDate(String buildDate) {
this.buildDate = buildDate;
}

public String getApplicationVersion() {
return applicationVersion;
}

public void setApplicationVersion(String applicationVersion) {
this.applicationVersion = applicationVersion;
}
}
Loading

0 comments on commit 7ea9906

Please sign in to comment.