├── .editorconfig
├── .gitattributes
├── .github
├── renovate.json
├── requirements.txt
└── workflows
│ ├── delete-workflow-runs.yml
│ ├── demo-android-agp7-ci-unreleased.yml
│ ├── demo-android-agp7-ci.yml
│ ├── demo-java-ci-unreleased.yml
│ ├── demo-java-ci.yml
│ ├── gradle-wrapper-validation.yml
│ ├── plugin-build-ci-all.yml
│ ├── plugin-build-ci.yml
│ ├── plugin-release-ci.yml
│ ├── quality-ci.yml
│ ├── quality-renovate.yml
│ └── wait-for-checks.yml
├── .gitignore
├── .pre-commit-config.yaml
├── LICENSE
├── README.adoc
├── build.gradle.kts
├── demo
├── android-agp7
│ ├── app
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── kotlin
│ │ │ └── org
│ │ │ │ └── jsonschema2dataclass
│ │ │ │ └── android
│ │ │ │ └── MainActivity.kt
│ │ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── menu
│ │ │ └── menu_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle.kts
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── lib
│ │ ├── build.gradle.kts
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── lib
│ │ │ └── AndroidLibExample.java
│ ├── lib2
│ │ ├── build.gradle.kts
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── org
│ │ │ │ └── jsonschema2dataclass
│ │ │ │ └── lib
│ │ │ │ └── AndroidLibExample.java
│ │ │ └── resources
│ │ │ └── json
│ │ │ └── entry.schema.json
│ ├── schema
│ │ └── entry.schema.json
│ └── settings.gradle
└── java
│ ├── build.gradle.kts
│ ├── classpath
│ ├── custom-rule-factory-apply
│ │ ├── build.gradle.kts
│ │ ├── gradle.properties
│ │ └── src
│ │ │ └── main
│ │ │ └── resources
│ │ │ └── json
│ │ │ └── custom-factory.json
│ ├── custom-rule-factory
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── example
│ │ │ ├── CustomFormatRule.java
│ │ │ └── CustomRuleFactory.java
│ ├── schema-reference
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── resources
│ │ │ └── schema
│ │ │ └── foo.json
│ └── schema
│ │ ├── build.gradle.kts
│ │ └── src
│ │ └── main
│ │ └── resources
│ │ └── schema
│ │ └── bar.json
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── groovy
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── org
│ │ │ └── js2d
│ │ │ └── AddressWork.java
│ │ └── resources
│ │ └── json
│ │ ├── address.json
│ │ └── external_dependencies.json
│ ├── kotlin
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ ├── kotlin
│ │ └── org
│ │ │ └── js2d
│ │ │ └── AddressWork.kt
│ │ └── resources
│ │ └── json
│ │ ├── address.json
│ │ └── external_dependencies.json
│ ├── model-publish
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── resources
│ │ └── json
│ │ ├── address.json
│ │ └── external_dependencies.json
│ └── settings.gradle.kts
├── docs
├── migration
│ ├── migration.adoc
│ ├── migration_5.adoc
│ └── migration_6.adoc
└── usage
│ ├── basic.adoc
│ ├── basic_2.adoc
│ ├── basic_3.adoc
│ ├── basic_4.adoc
│ ├── basic_5.adoc
│ ├── basic_6.adoc
│ ├── index.adoc
│ ├── parameters_5.adoc
│ └── parameters_6.adoc
├── gradle.properties
├── gradle
├── agp.dependencies.toml
├── init.gradle.kts
├── libs.dependencies.toml
├── plugins.dependencies.toml
├── processors.toml
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── internal
├── common
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── utils.kt
├── plugins
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── EnableFeaturePreviewQuietly.kt
│ │ └── org
│ │ └── jsonschema2dataclass
│ │ └── internal
│ │ └── plugin
│ │ ├── AGPCompat8Plugin.kt
│ │ ├── base
│ │ ├── GitVersion.kt
│ │ ├── GitVersionPlugin.kt
│ │ └── SettingEnterpriseAccept.kt
│ │ ├── lib
│ │ ├── GradlePlugin.kt
│ │ ├── KotlinToolchain.kt
│ │ ├── LibraryPlugin.kt
│ │ └── ProcessorVersionPlugin.kt
│ │ └── publishing
│ │ ├── PublishingPlugin.kt
│ │ ├── publishing.kt
│ │ └── signing.kt
└── settings.gradle.kts
├── plugin-gradle
├── common
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── org
│ │ └── jsonschema2dataclass
│ │ ├── ext
│ │ ├── Js2pExtension.kt
│ │ └── package-info.java
│ │ └── internal
│ │ ├── Js2dProcessor.kt
│ │ ├── RegisterTasks.kt
│ │ └── task
│ │ ├── Consts.kt
│ │ └── Js2dGeneratorTaskBase.kt
├── compat
│ ├── agp34
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── internal
│ │ │ └── compat
│ │ │ └── android
│ │ │ └── AGP34PluginRegistration.kt
│ ├── agp7
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── internal
│ │ │ └── compat
│ │ │ └── android
│ │ │ └── AGP347PluginRegistration.kt
│ ├── android
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── internal
│ │ │ └── compat
│ │ │ └── android
│ │ │ └── Register.kt
│ ├── java
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ └── internal
│ │ │ └── compat
│ │ │ └── java
│ │ │ └── JavaPluginRegistration.kt
│ └── kotlin
│ │ ├── build.gradle.kts
│ │ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── org
│ │ └── jsonschema2dataclass
│ │ └── internal
│ │ └── compat
│ │ └── kotlin
│ │ ├── KotlinCompat.kt
│ │ └── TestsNeeded.kt
├── plugin
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── org
│ │ │ └── jsonschema2dataclass
│ │ │ ├── Js2dPlugin.kt
│ │ │ └── internal
│ │ │ ├── Checks.kt
│ │ │ └── TaskGeneration.kt
│ │ └── test
│ │ └── kotlin
│ │ └── org
│ │ └── jsonschema2dataclass
│ │ └── js2p
│ │ ├── GradleVersions.kt
│ │ ├── JavaTaskFunctionalTest.kt
│ │ ├── TestCasesGenerator.kt
│ │ ├── TestUtils.kt
│ │ └── internal
│ │ └── NameGeneratorTest.kt
└── processors
│ └── jsonschema2pojo
│ ├── build.gradle.kts
│ └── src
│ ├── main
│ └── kotlin
│ │ └── org
│ │ └── jsonschema2dataclass
│ │ └── internal
│ │ └── js2p
│ │ ├── Js2pConfig.kt
│ │ ├── Js2pGenerationTask.kt
│ │ ├── Js2pProcessor.kt
│ │ ├── Js2pWokerConfig.kt
│ │ └── Js2pWorker.kt
│ └── test
│ └── kotlin
│ └── org
│ └── jsonschema2dataclass
│ └── internal
│ ├── Randomizer.kt
│ └── js2p
│ ├── EqualityChecks.kt
│ ├── Randomizer.kt
│ ├── SimpleGenerationConfig.kt
│ └── WorkerConvertTest.kt
└── settings.gradle.kts
/.editorconfig:
--------------------------------------------------------------------------------
1 | root=true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 | tab_width = 4
7 | indent_size = 4
8 | indent_style = space
9 | trim_trailing_whitespace = true
10 | charset = utf-8
11 |
12 | # The JSON files contain newlines inconsistently
13 | [*.json]
14 | indent_size = 2
15 | tab_width = 2
16 | insert_final_newline = false
17 |
18 | [*.{yml,yaml}]
19 | tab_width = 2
20 | indent_size = 2
21 |
22 | [*.diff]
23 | trim_trailing_whitespace = false
24 |
25 | [COMMIT_EDITMSG]
26 | trim_trailing_whitespace = false
27 |
28 |
29 | [*.{kt,kts}]
30 | max_line_length = 120
31 | ktlint_standard_no-wildcard-imports = enabled
32 | ktlint_standard_filename = disabled
33 | ktlint_standard_multiline-expression-wrapping = disabled
34 | ktlint_standard_string-template-indent = disabled
35 | ktlint_standard_function-signature = disabled
36 | ktlint_standard_annotation = disabled
37 | ktlint_standard_parameter-list-wrapping = disabled
38 |
39 | # enable trailing commas per JetBrains recommendation
40 | # (https://kotlinlang.org/docs/coding-conventions.html#trailing-commas)
41 | ij_kotlin_allow_trailing_comma_on_call_site = true
42 | ij_kotlin_allow_trailing_comma = true
43 | ij_kotlin_name_count_to_use_star_import = 100
44 | ij_kotlin_name_count_to_use_star_import_for_members = 100
45 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | gradlew text eol=lf
2 | gradlew.bat text eol=crlf
3 |
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "commitMessageExtra": "from {{{currentValue}}} to {{{newValue}}}{{#if isMajor}} (major v{{{newMajor}}}){{else}}{{/if}}",
4 | "extends": [
5 | "config:base"
6 | ],
7 | "packageRules": [
8 | {
9 | "description": "Disable updating AGP compatibility dependencies. Allow changes in minor and patches.",
10 | "enabled": false,
11 | "matchFiles": [
12 | "gradle/agp.dependencies.toml",
13 | "demo/android-agp7/**"
14 | ],
15 | "matchPackageNames": [
16 | "com.android.tools.build:gradle"
17 | ],
18 | "matchUpdateTypes": [
19 | "major"
20 | ]
21 | }
22 | ],
23 | "pre-commit": {
24 | "enabled": true
25 | },
26 | "separateMajorMinor": true,
27 | "separateMinorPatch": true,
28 | "separateMultipleMajor": true
29 | }
30 |
--------------------------------------------------------------------------------
/.github/requirements.txt:
--------------------------------------------------------------------------------
1 | pre-commit==4.2.0
2 |
--------------------------------------------------------------------------------
/.github/workflows/delete-workflow-runs.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Delete old workflow runs
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | days:
7 | description: Days-worth of runs to keep for each workflow
8 | required: true
9 | default: '90'
10 | minimum_runs:
11 | description: Minimum runs to keep for each workflow
12 | required: true
13 | default: '6'
14 | delete_workflow_pattern:
15 | description: Name or filename of the workflow (if not set, all workflows are targeted)
16 | required: false
17 | delete_workflow_by_state_pattern:
18 | description: 'Filter workflows by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
19 | required: true
20 | default: ALL
21 | type: choice
22 | options:
23 | - ALL
24 | - active
25 | - deleted
26 | - disabled_inactivity
27 | - disabled_manually
28 | delete_run_by_conclusion_pattern:
29 | description: 'Remove runs based on conclusion: action_required, cancelled, failure, skipped, success'
30 | required: true
31 | default: ALL
32 | type: choice
33 | options:
34 | - ALL
35 | - 'Unsuccessful: action_required,cancelled,failure,skipped'
36 | - action_required
37 | - cancelled
38 | - failure
39 | - skipped
40 | - success
41 | dry_run:
42 | description: Logs simulated changes, no deletions are performed
43 | required: false
44 |
45 | jobs:
46 | del_runs:
47 | runs-on: ubuntu-latest
48 | permissions:
49 | actions: write
50 | contents: read
51 | steps:
52 | - name: Delete workflow runs
53 | uses: Mattraks/delete-workflow-runs@v2
54 | with:
55 | token: ${{ github.token }}
56 | repository: ${{ github.repository }}
57 | retain_days: ${{ github.event.inputs.days }}
58 | keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
59 | delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
60 | delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
61 | delete_run_by_conclusion_pattern: >-
62 | ${{
63 | startsWith(github.event.inputs.delete_run_by_conclusion_pattern, 'Unsuccessful:')
64 | && 'action_required,cancelled,failure,skipped'
65 | || github.event.inputs.delete_run_by_conclusion_pattern
66 | }}
67 | dry_run: ${{ github.event.inputs.dry_run }}
68 |
--------------------------------------------------------------------------------
/.github/workflows/demo-android-agp7-ci-unreleased.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Android AGP 7 Demo CI (unreleased plugin version)
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | tags-ignore:
9 | - '*'
10 | paths:
11 | - build.gradle.kts
12 | - internal/**
13 | - plugin-gradle/**
14 | - demo/android-agp7/**
15 | - .github/workflows/demo-android-agp7-ci-unreleased.yml
16 | pull_request:
17 | types: [assigned, opened, synchronize, reopened]
18 | paths:
19 | - plugin-gradle/**
20 | - demo/android-agp7/**
21 | - .github/workflows/demo-android-agp7-ci-unreleased.yml
22 |
23 | concurrency:
24 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
25 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
26 | group: ${{ github.ref == 'refs/heads/main' && format('demo-agp7-ci-un-main-{0}', github.sha) || format('demo-agp7-ci-un-{0}', github.ref) }}
27 | cancel-in-progress: true
28 |
29 | env:
30 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
31 |
32 | jobs:
33 | buildDemo:
34 | name: Build Android AGP 7 Demo (unreleased plugin version)
35 | runs-on: ubuntu-latest
36 | defaults:
37 | run:
38 | working-directory: demo/android-agp7
39 | strategy:
40 | fail-fast: false
41 | matrix:
42 | java: [17]
43 | distribution: [zulu]
44 | steps:
45 | - name: Checkout
46 | uses: actions/checkout@v4
47 | - name: Set up JDK ${{ matrix.distribution }} ${{ matrix.java }}
48 | uses: actions/setup-java@v4
49 | with:
50 | distribution: ${{ matrix.distribution }}
51 | java-version: ${{ matrix.java }}
52 | cache: gradle
53 | - name: Install Android SDK
54 | uses: malinskiy/action-android/install-sdk@release/0.1.4
55 | - name: Build project Android AGP 7 Demo (unreleased plugin version)
56 | run: ./gradlew assembleDebug -S --scan --warning-mode all -I ../../gradle/init.gradle.kts
57 |
--------------------------------------------------------------------------------
/.github/workflows/demo-android-agp7-ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Android AGP 7 Demo CI
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | tags-ignore:
9 | - '*'
10 | paths:
11 | - demo/android-agp7/**
12 | - .github/workflows/demo-android-agp7-ci.yml
13 | pull_request:
14 | types: [assigned, opened, synchronize, reopened]
15 | paths:
16 | - demo/android-agp7/**
17 | - .github/workflows/demo-android-agp7-ci.yml
18 |
19 | concurrency:
20 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
21 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
22 | group: ${{ github.ref == 'refs/heads/main' && format('demo-agp7-ci-main-{0}', github.sha) || format('demo-agp7-ci-{0}', github.ref) }}
23 | cancel-in-progress: true
24 |
25 | env:
26 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
27 |
28 | jobs:
29 | buildDemo:
30 | name: Build Android AGP 7 Demo
31 | runs-on: ubuntu-latest
32 | defaults:
33 | run:
34 | working-directory: demo/android-agp7
35 | strategy:
36 | fail-fast: false
37 | max-parallel: 2
38 | matrix:
39 | java: [11, 17, 18]
40 | distribution: [zulu, temurin]
41 | steps:
42 | - name: Checkout
43 | uses: actions/checkout@v4
44 | - name: Set up JDK ${{ matrix.distribution }} ${{ matrix.java }}
45 | uses: actions/setup-java@v4
46 | with:
47 | distribution: ${{ matrix.distribution }}
48 | java-version: ${{ matrix.java }}
49 | cache: gradle
50 | - name: Install Android SDK
51 | uses: malinskiy/action-android/install-sdk@release/0.1.4
52 | - name: Build project Android AGP 7 Demo
53 | run: ./gradlew assembleDebug -S --scan --warning-mode all
54 |
--------------------------------------------------------------------------------
/.github/workflows/demo-java-ci-unreleased.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Java Demo CI (unreleased plugin version)
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | tags-ignore:
9 | - '*'
10 | paths:
11 | - build.gradle.kts
12 | - internal/**
13 | - plugin-gradle/**
14 | - demo/java/**
15 | - .github/workflows/demo-java-ci-unreleased.yml
16 | pull_request:
17 | types: [assigned, opened, synchronize, reopened]
18 | paths:
19 | - plugin-gradle/**
20 | - demo/java/**
21 | - .github/workflows/demo-java-ci-unreleased.yml
22 |
23 | concurrency:
24 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
25 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
26 | group: ${{ github.ref == 'refs/heads/main' && format('demo-java-ci-un-main-{0}', github.sha) || format('demo-java-ci-un-{0}', github.ref) }}
27 | cancel-in-progress: true
28 |
29 | env:
30 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
31 |
32 | jobs:
33 | buildTest:
34 | name: Build Java Demos (unreleased plugin version)
35 | runs-on: ubuntu-latest
36 | defaults:
37 | run:
38 | working-directory: demo/java
39 | strategy:
40 | fail-fast: false
41 | max-parallel: 1
42 | matrix:
43 | java_version: [8, 17]
44 | distribution: [zulu]
45 | steps:
46 | - name: Checkout
47 | uses: actions/checkout@v4
48 | - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }}
49 | uses: actions/setup-java@v4
50 | with:
51 | distribution: ${{ matrix.distribution }}
52 | java-version: ${{ matrix.java_version }}
53 | cache: gradle
54 | - name: Build project Java Demo (unreleased plugin version)
55 | run: ./gradlew build -S --scan --warning-mode all -I ../../gradle/init.gradle.kts
56 |
--------------------------------------------------------------------------------
/.github/workflows/demo-java-ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Java Demo CI
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | tags-ignore:
9 | - '*'
10 | paths:
11 | - demo/java/**
12 | - .github/workflows/demo-java-ci.yml
13 | pull_request:
14 | types: [assigned, opened, synchronize, reopened]
15 | paths:
16 | - demo/java/**
17 | - .github/workflows/demo-java-ci.yml
18 |
19 | concurrency:
20 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
21 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
22 | group: ${{ github.ref == 'refs/heads/main' && format('demo-java-ci-main-{0}', github.sha) || format('demo-java-ci-{0}', github.ref) }}
23 | cancel-in-progress: true
24 |
25 | env:
26 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
27 |
28 | jobs:
29 | buildTest:
30 | name: Build Java Demos
31 | runs-on: ubuntu-latest
32 | defaults:
33 | run:
34 | working-directory: demo/java
35 | strategy:
36 | max-parallel: 2
37 | fail-fast: false
38 | matrix:
39 | java_version: [8, 11, 17, 19]
40 | distribution: [zulu, temurin]
41 | steps:
42 | - name: Checkout
43 | uses: actions/checkout@v4
44 | - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }}
45 | uses: actions/setup-java@v4
46 | with:
47 | distribution: ${{ matrix.distribution }}
48 | java-version: ${{ matrix.java_version }}
49 | cache: gradle
50 | - name: Build project Java Demo
51 | run: ./gradlew build -S --scan --warning-mode all
52 |
--------------------------------------------------------------------------------
/.github/workflows/gradle-wrapper-validation.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Validate Gradle Wrapper
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | paths:
9 | - gradle/wrapper/**
10 | - demo/android-agp7/gradle/wrapper/**
11 | - demo/java/gradle/wrapper/**
12 | - .github/workflows/gradle-wrapper-validation.yml
13 | pull_request:
14 | branches:
15 | - main
16 | paths:
17 | - gradle/wrapper/**
18 | - demo/android-agp7/gradle/**
19 | - demo/java/gradle/**
20 | - .github/workflows/gradle-wrapper-validation.yml
21 |
22 | concurrency:
23 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
24 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
25 | group: ${{ github.ref == 'refs/heads/main' && format('gradle-wrapper-validation-main-{0}', github.sha) || format('gradle-wrapper-validation-{0}', github.ref)
26 | }}
27 | cancel-in-progress: true
28 |
29 | env:
30 | GRADLE_OPTS: -Dorg.gradle.daemon=false -Dkotlin.incremental=false -Dkotlin.compiler.execution.strategy=in-process
31 |
32 | jobs:
33 | validationPlugin:
34 | name: 'Wrapper validation: Plugin'
35 | runs-on: ubuntu-latest
36 | steps:
37 | - uses: actions/checkout@v4
38 | with:
39 | fetch-depth: 0
40 | - uses: gradle/wrapper-validation-action@v3
41 | validationJavaKotlinSample:
42 | name: 'Wrapper validation: Java Demo'
43 | runs-on: ubuntu-latest
44 | defaults:
45 | run:
46 | working-directory: demo/java
47 | steps:
48 | - uses: actions/checkout@v4
49 | with:
50 | fetch-depth: 0
51 | - uses: gradle/wrapper-validation-action@v3
52 | validationAndroidAgp7Sample:
53 | name: 'Wrapper validation: Android AGP 7 Demo'
54 | runs-on: ubuntu-latest
55 | defaults:
56 | run:
57 | working-directory: demo/android-agp7
58 | steps:
59 | - uses: actions/checkout@v4
60 | with:
61 | fetch-depth: 0
62 | - uses: gradle/wrapper-validation-action@v3
63 |
--------------------------------------------------------------------------------
/.github/workflows/plugin-build-ci-all.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Build Plugin CI manual
3 |
4 | on:
5 | workflow_dispatch:
6 | inputs:
7 | gradleTest:
8 | type: choice
9 | description: Gradle versions to run tests on
10 | options:
11 | - all
12 | - current
13 | - '8'
14 | - '7'
15 | - '6'
16 | java:
17 | type: choice
18 | description: Java versions to run tests with
19 | options:
20 | - '21'
21 | - '17'
22 | - '11'
23 | - '8'
24 | distribution:
25 | type: choice
26 | description: Java distribution to use
27 | options:
28 | - zulu
29 |
30 | concurrency:
31 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
32 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
33 | group: ${{ github.ref == 'refs/heads/main' && format('plugin-build-ci-man-main-{0}', github.sha) || format('plugin-build-ci-man-{0}', github.ref) }}
34 | cancel-in-progress: true
35 |
36 | env:
37 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
38 |
39 | jobs:
40 | build-and-test:
41 | name: Build Plugin
42 | runs-on: ubuntu-latest
43 | steps:
44 | - uses: actions/checkout@v4
45 | - name: Set up JDK ${{ github.event.inputs.distribution }} ${{ github.event.inputs.java }} for gradle test ${{ github.event.inputs.gradleTest }}
46 | uses: actions/setup-java@v4
47 | with:
48 | distribution: ${{ github.event.inputs.distribution }}
49 | java-version: ${{ github.event.inputs.java }}
50 | cache: gradle
51 |
52 | - name: Run build and tests
53 | run: |
54 | if [[ "${{ github.event.inputs.gradleTest }}" == "all" ]]; then
55 | # DO NADA
56 | elif [[ "${{ github.event.inputs.gradleTest }}" == "current" ]]; then
57 | export TEST_GRADLE_VER_EXACT=current
58 | else
59 | export TEST_GRADLE_VER_MIN=${{ github.event.inputs.gradleTest }}
60 | export TEST_GRADLE_VER_MAX=$(( ${{ github.event.inputs.gradleTest }} + 1))
61 | fi
62 |
63 | ./gradlew build -S --scan --warning-mode all --no-daemon
64 |
--------------------------------------------------------------------------------
/.github/workflows/plugin-build-ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Build Plugin CI
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 | tags-ignore:
9 | - '*'
10 | paths:
11 | - plugin-gradle/**
12 | - gradle/wrapper/**
13 | - gradle/agp.dependencies.toml
14 | - gradle/libs.dependencies.toml
15 | - gradle/processors.toml
16 | - gradle/plugins.dependencies.toml
17 | - gradlew*
18 | - internal/plugins/**
19 | - internal/common/**
20 | - internal/settings.gradle.kts
21 | - settings.gradle.kts
22 | - build.gradle.kts
23 | - gradle.properties
24 | - .github/workflows/plugin-build-ci.yml
25 | pull_request:
26 | types: [assigned, opened, synchronize, reopened]
27 | paths:
28 | - plugin-gradle/**
29 | - gradle/wrapper/**
30 | - gradle/agp.dependencies.toml
31 | - gradle/libs.dependencies.toml
32 | - gradle/processors.toml
33 | - gradle/plugins.dependencies.toml
34 | - gradlew*
35 | - internal/plugins/**
36 | - internal/common/**
37 | - internal/settings.gradle.kts
38 | - settings.gradle.kts
39 | - build.gradle.kts
40 | - gradle.properties
41 | - .github/workflows/plugin-build-ci.yml
42 |
43 | concurrency:
44 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
45 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
46 | group: ${{ github.ref == 'refs/heads/main' && format('plugin-build-ci-main-{0}', github.sha) || format('plugin-build-ci-{0}', github.ref) }}
47 | cancel-in-progress: true
48 |
49 | env:
50 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
51 |
52 | jobs:
53 | build-and-test:
54 | name: Build Plugin
55 | runs-on: ubuntu-latest
56 | strategy:
57 | fail-fast: false
58 | max-parallel: 2
59 | matrix:
60 | gradleTest: [current, 8, 7]
61 | java: [21, 17]
62 | distribution: [zulu]
63 | steps:
64 | - uses: actions/checkout@v4
65 | - name: Set up JDK ${{ matrix.distribution }} ${{ matrix.java }} for gradle test ${{ matrix.gradleTest }}
66 | uses: actions/setup-java@v4
67 | with:
68 | distribution: ${{ matrix.distribution }}
69 | java-version: ${{ matrix.java }}
70 | cache: gradle
71 |
72 | - name: Run build and tests
73 | run: |
74 | if [[ "${{ matrix.gradleTest }}" == "current" ]]; then
75 | export TEST_GRADLE_VER_EXACT=current
76 | else
77 | export TEST_GRADLE_VER_MIN=${{ matrix.gradleTest }}
78 | export TEST_GRADLE_VER_MAX=$(( ${{ matrix.gradleTest }} + 1))
79 | fi
80 | ./gradlew build -S --scan --warning-mode all --no-daemon
81 |
--------------------------------------------------------------------------------
/.github/workflows/plugin-release-ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Release Plugin
3 |
4 | on:
5 | push:
6 | tags:
7 | - v[0-9]+.[0-9]+.[0-9]+
8 | - v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+
9 |
10 | concurrency:
11 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
12 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
13 | group: ${{ github.ref == 'refs/heads/main' && format('demo-agp7-ci-main-{0}', github.sha) || format('demo-agp7-ci-{0}', github.ref) }}
14 | cancel-in-progress: true
15 |
16 | env:
17 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
18 |
19 | jobs:
20 | publish:
21 | name: Publish release
22 | runs-on: ubuntu-latest
23 | environment: production
24 | steps:
25 | - name: Checkout
26 | uses: actions/checkout@v4
27 | with:
28 | fetch-depth: 0
29 | - name: Install JDK 17
30 | uses: actions/setup-java@v4
31 | with:
32 | distribution: temurin
33 | java-version: 17
34 | cache: gradle
35 | - name: Build project
36 | run: ./gradlew build --no-daemon -Porg.jsonschema2dataclass.internal.git-version=true
37 | env:
38 | VERSION: ${{ github.ref }}
39 | - name: Find Tag
40 | id: tagger
41 | uses: jimschubert/query-tag-action@v2
42 | with:
43 | skip-unshallow: 'true'
44 | commit-ish: HEAD
45 | - name: Create Github release
46 | run: |
47 | PRE_RELEASE=""
48 | if [[ ${{steps.tagger.outputs.tag}} == *"beta"* ]]; then
49 | PRE_RELEASE="-p"
50 | fi
51 | if [[ ${{steps.tagger.outputs.tag}} == *"alpha"* ]]; then
52 | PRE_RELEASE="-p"
53 | fi
54 | if [[ ${{steps.tagger.outputs.tag}} == *"rc"* ]]; then
55 | PRE_RELEASE="-p"
56 | fi
57 | set -x
58 | hub release create $PRE_RELEASE -m "${{steps.tagger.outputs.tag}}" "${{steps.tagger.outputs.tag}}"
59 | env:
60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61 | VERSION: ${{steps.tagger.outputs.tag}}
62 | - name: Publish
63 | uses: burrunan/gradle-cache-action@v3.0
64 | with:
65 | remote-build-cache-proxy-enabled: false
66 | properties: |
67 | gradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }}
68 | gradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }}
69 | arguments: publishPlugins -s --scan --no-daemon
70 |
--------------------------------------------------------------------------------
/.github/workflows/quality-ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Verify Quality Checks
3 |
4 | on:
5 | pull_request:
6 | types: [assigned, opened, synchronize, reopened]
7 |
8 | concurrency:
9 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
10 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
11 | group: ${{ github.ref == 'refs/heads/main' && format('quality-ci-main-{0}', github.sha) || format('quality-ci-{0}', github.ref) }}
12 | cancel-in-progress: true
13 |
14 | env:
15 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false
16 |
17 | jobs:
18 | pre-commit:
19 | name: Pre-commit checks
20 | runs-on: ubuntu-latest
21 | steps:
22 | - uses: actions/checkout@v4
23 | - uses: actions/setup-python@v5
24 | with:
25 | python-version: '3.13'
26 | cache: pip
27 | - name: Install dependencies
28 | run: |
29 | pip install -U pip setuptools wheel
30 | pip install -r .github/requirements.txt
31 | - uses: actions/cache@v4
32 | with:
33 | path: ~/.cache/pre-commit/
34 | key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
35 | - name: Run pre-commit hooks
36 | run: pre-commit run --all-files --show-diff-on-failure
37 |
--------------------------------------------------------------------------------
/.github/workflows/quality-renovate.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Verify Quality Checks
3 |
4 | on:
5 |
6 | pull_request:
7 | types: [assigned, opened, synchronize, reopened]
8 | paths:
9 | - .github/renovate.json
10 | - .github/workflows/renovate-verify.yml
11 |
12 | concurrency:
13 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
14 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
15 | group: ${{ github.ref == 'refs/heads/main' && format('quality-renovate-main-{0}', github.sha) || format('quality-renovate-{0}', github.ref) }}
16 | cancel-in-progress: true
17 |
18 | jobs:
19 | verify-renovate:
20 | name: Renovate official check
21 | runs-on: ubuntu-latest
22 | steps:
23 | - uses: actions/checkout@v4
24 | - uses: actions/setup-node@v4
25 | - run: npx --package renovate -c 'renovate-config-validator'
26 |
--------------------------------------------------------------------------------
/.github/workflows/wait-for-checks.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Wait all checks
3 |
4 | on:
5 | pull_request:
6 | types: [assigned, opened, synchronize, reopened]
7 |
8 | concurrency:
9 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
10 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
11 | group: ${{ github.ref == 'refs/heads/main' && format('wait-for-checks-main-{0}', github.sha) || format('wait-for-checks-{0}', github.ref) }}
12 | cancel-in-progress: true
13 |
14 | jobs:
15 | wait-all-checks:
16 | runs-on: ubuntu-latest
17 | permissions:
18 | checks: read
19 | steps:
20 | - name: Wait all GitHub checks
21 | uses: poseidon/wait-for-status-checks@v0.6.0
22 | with:
23 | token: ${{ secrets.GITHUB_TOKEN }}
24 | ignore: wait-all-checks / wait-all-checks
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.hprof
2 | .idea
3 | .gradle
4 | build
5 | local.properties
6 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | repos:
3 | - repo: https://github.com/pre-commit/pre-commit-hooks
4 | rev: v5.0.0
5 | hooks:
6 | - id: check-case-conflict
7 | - id: check-merge-conflict
8 | - id: check-json
9 | - id: check-symlinks
10 | - id: end-of-file-fixer
11 | - id: pretty-format-json
12 | args: [--autofix]
13 | - id: trailing-whitespace
14 | - repo: https://github.com/Lucas-C/pre-commit-hooks
15 | rev: v1.5.5
16 | hooks:
17 | - id: forbid-crlf
18 | exclude: .*gradlew.bat
19 | - id: forbid-tabs
20 | - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
21 | rev: 0.2.3
22 | hooks:
23 | - id: yamlfmt
24 | args: [--mapping, '2', --sequence, '2', --offset, '0', --width, '150']
25 | - repo: https://github.com/python-jsonschema/check-jsonschema
26 | rev: 0.32.1
27 | hooks:
28 | - id: check-github-workflows
29 | - id: check-renovate
30 | - repo: https://github.com/eirnym/language-formatters-pre-commit-hooks
31 | rev: ev2.14.0
32 | hooks:
33 | - id: pretty-format-kotlin
34 | args: [--autofix]
35 | - id: pretty-format-java
36 | args: [--autofix, --palantir]
37 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | :toc:
2 | :toc-placement: preamble
3 | :toclevels: 1
4 | :showtitle:
5 |
6 | :plugin_major: 6
7 |
8 | = Json Schema to Data Class Gradle plugin
9 |
10 | image:https://img.shields.io/github/v/release/jsonschema2dataclass/js2d-gradle[GitHub release (latest by date)]
11 |
12 | // Need some preamble to get TOC:
13 | {empty}
14 |
15 | == Introduction
16 |
17 | This plugin is aiming to take raw JSON or YAML raw files or schemas and convert definitions to Java POJOs
18 | (Plain Old Java Object).
19 |
20 | At the moment of writing documentation, it uses
21 | https://github.com/joelittlejohn/jsonschema2pojo[jsonschema2pojo] 1.2.1 library to generate classes.
22 |
23 | The `org.jsonschema2dataclass` plugin feature highlight:
24 |
25 | * Full support and testing for wide version range of versions of Java, Gradle and AGP
26 | including task caching, proper hooking and other features.
27 | +
28 | Currently, it's Java 1.8 to 19, Gradle 6.0 to 7.6 and AGP 3, 4 and 7.
29 | Additionally, plugin has beta support for Gradle 8.0 and AGP 8.
30 |
31 | * Possibility natively write Gradle scripts in Groovy and Kotlin DSLs.
32 | * Support for projects written in Kotlin and Groovy and which are using Lombok.
33 | * Possibility to run multiple executions withing a single project.
34 | +
35 | This is important for some use cases to generate different sets of models within a single project.
36 | * Some parameters are more human-writable and using native features provided by Gradle.
37 | +
38 | --
39 | .Few examples
40 | ** `propertyWordDelimiters` is array of chars in `jsonschema2pojo`, which is not easy to write and support.
41 | ** `org.jsonschema2dataclass` uses Gradle-provided structures for all configuration parameters.
42 | --
43 | * Plugin is not tied to the library interface and could provide more maintainable configuration presentation
44 | and wider feature range when needed.
45 |
46 | Please note, that JSON schema constrains can be quite poorly translated to JSR305 and in most cases
47 | can't replace Json Schema Validation.
48 | I suggest to use a Json Schema Validation library when possible like one
49 | https://github.com/networknt/json-schema-validator[by NetworkNT].
50 |
51 | == Usage and migration information for {plugin_major}.x
52 |
53 | Usage and migration documentation is located in separate documents.
54 |
55 | * xref:docs/usage/basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x]
56 | * xref:docs/usage/parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x]
57 | * xref:docs/migration/migration_{plugin_major}.adoc[Migration guide for {plugin_major}.x]
58 |
59 | == Usage and migration information for all versions
60 |
61 | Usage and migration documentation is located in separate documents.
62 |
63 | * xref:docs/usage/index.adoc[Usage documentation for all versions]
64 | * xref:docs/migration/migration.adoc[Migration guides for all versions]
65 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(pluginDeps.plugins.gradle.publish) apply false
3 | id("org.jsonschema2dataclass.internal.git-version")
4 | }
5 |
6 | val projectVersion: Any = project.version
7 |
8 | allprojects {
9 | group = "org.jsonschema2dataclass"
10 | version = projectVersion
11 | }
12 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id "org.jsonschema2dataclass"
4 | id "kotlin-android"
5 | }
6 |
7 | android {
8 | namespace "org.jsonschema2dataclass.android"
9 |
10 | compileSdkVersion 34
11 | sourceSets {
12 | debug.java.srcDirs +='build/generated/sources/js2d/main/debug'
13 | release.java.srcDirs +='build/generated/sources/js2d/main/release'
14 | }
15 | defaultConfig {
16 | applicationId "org.jsonschema2dataclass.android"
17 | minSdkVersion 24
18 | targetSdkVersion 34
19 | versionCode 1
20 | versionName "1.0"
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 |
29 | packagingOptions {
30 | exclude 'META-INF/LICENSE.txt'
31 | }
32 | compileOptions {
33 | sourceCompatibility = JavaVersion.current()
34 | targetCompatibility = JavaVersion.current()
35 | }
36 | kotlin {
37 | jvmToolchain {
38 | languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion.toInteger()))
39 | }
40 | }
41 | }
42 |
43 | dependencies {
44 | implementation 'androidx.appcompat:appcompat:1.6.1'
45 |
46 | implementation 'com.google.code.gson:gson:2.11.0'
47 | // Required if generating JSR-303 annotations
48 | implementation 'javax.validation:validation-api:2.0.1.Final'
49 | implementation "androidx.core:core-ktx:1.13.1"
50 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.20"
51 | }
52 |
53 | jsonSchema2Pojo {
54 | executions {
55 | main {
56 | io {
57 | source.setFrom(files("${project.rootDir}/schema"))
58 | sourceType.set("jsonschema")
59 | outputEncoding.set("UTF-8")
60 | delimitersPropertyWord.set("")
61 | }
62 |
63 | klass {
64 | targetPackage.set("com.oosocial.clarityn.rest.clarityn.model")
65 | annotationStyle.set("gson")
66 | customAnnotatorClass.set("org.jsonschema2pojo.NoopAnnotator")
67 | }
68 |
69 | methods {
70 | builders.set(false)
71 | hashcodeAndEquals.set(true)
72 | toStringMethod.set(true)
73 | annotateJsr303.set(true)
74 | }
75 |
76 | fields {
77 | usePrimitives.set(false)
78 | integerUseLong.set(false)
79 | floatUseDouble.set(true)
80 | initializeCollections.set(true)
81 | }
82 |
83 | dateTime.jodaDate.set(false)
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/sduke/Android-SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.kts.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/kotlin/org/jsonschema2dataclass/android/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.android
2 |
3 | import android.os.Bundle
4 | import android.view.Menu
5 | import android.view.MenuItem
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.oosocial.clarityn.rest.clarityn.model.EntrySchema
8 | import com.oosocial.clarityn.rest.clarityn.model.Storage
9 |
10 | class MainActivity : AppCompatActivity() {
11 | private lateinit var schema: EntrySchema
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_main)
16 | schema = EntrySchema()
17 | schema.readonly = false
18 | schema.fstype = EntrySchema.Fstype.EXT_4
19 | schema.storage = Storage()
20 | }
21 |
22 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
23 | menuInflater.inflate(R.menu.menu_main, menu)
24 | return true
25 | }
26 |
27 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
28 | val id = item.itemId
29 | return if (id == R.id.action_settings) {
30 | true
31 | } else {
32 | super.onOptionsItemSelected(item)
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/android-agp7/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/android-agp7/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/android-agp7/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/android-agp7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidExample
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/demo/android-agp7/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/demo/android-agp7/build.gradle.kts:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | dependencies {
8 | classpath("com.android.tools.build:gradle:7.4.2")
9 | classpath("org.jsonschema2dataclass:plugin:6.0.0")
10 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20")
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/demo/android-agp7/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier=true
2 | android.useAndroidX=true
3 | android.jetifier.ignorelist=jackson-core,jackson-databind
4 |
--------------------------------------------------------------------------------
/demo/android-agp7/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/android-agp7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/demo/android-agp7/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/demo/android-agp7/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("org.jetbrains.kotlin.android")
4 | id("org.jsonschema2dataclass")
5 | }
6 |
7 | android {
8 | namespace = "org.jsonschema2dataclass.lib"
9 |
10 | compileSdkVersion = "android-35"
11 |
12 | defaultConfig {
13 | minSdk = 24
14 | targetSdk = 35
15 | }
16 | buildTypes {
17 | release {
18 | isMinifyEnabled = false
19 | consumerProguardFiles("proguard-rules.pro")
20 | }
21 | }
22 |
23 | packagingOptions {
24 | resources.excludes.add("META-INF/LICENSE.txt")
25 | }
26 | compileOptions {
27 | sourceCompatibility = JavaVersion.current()
28 | targetCompatibility = JavaVersion.current()
29 | }
30 | kotlin {
31 | jvmToolchain {
32 | languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion.toInt()))
33 | }
34 | }
35 | }
36 |
37 | dependencies {
38 | implementation("androidx.appcompat:appcompat:1.6.1")
39 |
40 | // Required for @Generated annotation
41 | implementation("org.glassfish:javax.annotation:10.0-b28")
42 | implementation("com.google.code.gson:gson:2.11.0")
43 | implementation("com.squareup.moshi:moshi:1.15.2")
44 | // Required if generating JSR-303 annotations
45 | implementation("javax.validation:validation-api:2.0.1.Final")
46 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
47 | implementation("androidx.core:core-ktx:1.13.1")
48 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.20")
49 | }
50 |
51 | jsonSchema2Pojo {
52 | executions {
53 | create("main") {
54 | io {
55 | source.setFrom(files("${project.rootDir}/schema"))
56 | sourceType.set("jsonschema")
57 | outputEncoding.set("UTF-8")
58 | delimitersPropertyWord.set("")
59 | }
60 |
61 | klass {
62 | targetPackage.set("com.oosocial.clarityn.rest.clarityn.model")
63 | annotationStyle.set("gson")
64 | customAnnotatorClass.set("org.jsonschema2pojo.NoopAnnotator")
65 | }
66 |
67 | methods {
68 | builders.set(false)
69 | hashcodeAndEquals.set(true)
70 | toStringMethod.set(true)
71 | annotateJsr303.set(true)
72 | }
73 |
74 | fields {
75 | usePrimitives.set(false)
76 | integerUseLong.set(false)
77 | floatUseDouble.set(true)
78 | initializeCollections.set(true)
79 | }
80 |
81 | dateTime.jodaDate.set(false)
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/android/android-sdk-linux/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.kts.kts.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib/src/main/java/org/jsonschema2dataclass/lib/AndroidLibExample.java:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.lib;
2 |
3 | import com.oosocial.clarityn.rest.clarityn.model.EntrySchema;
4 | import com.oosocial.clarityn.rest.clarityn.model.Storage;
5 |
6 | public final class AndroidLibExample {
7 |
8 | public static void example() {
9 | EntrySchema schema = new EntrySchema();
10 | schema.setReadonly(false);
11 | schema.setFstype(EntrySchema.Fstype.EXT_4);
12 | schema.setStorage(new Storage());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib2/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("org.jetbrains.kotlin.android")
4 | id("org.jsonschema2dataclass")
5 | }
6 |
7 | android {
8 | namespace = "org.jsonschema2dataclass.lib2"
9 | compileSdk = 34
10 |
11 | defaultConfig {
12 | minSdk = 24
13 | targetSdk = 34
14 |
15 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles("consumer-rules.pro")
17 | }
18 |
19 | buildTypes {
20 | release {
21 | isMinifyEnabled = false
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility = JavaVersion.current()
26 | targetCompatibility = JavaVersion.current()
27 | }
28 | kotlin {
29 | jvmToolchain {
30 | languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion.toInt()))
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | implementation("androidx.core:core-ktx:1.13.1")
37 | implementation("androidx.appcompat:appcompat:1.6.1")
38 | implementation("com.google.android.material:material:1.12.0")
39 | implementation("com.google.code.gson:gson:2.11.0")
40 | androidTestImplementation("junit:junit:4.13.2")
41 | androidTestImplementation("androidx.test.ext:junit:1.2.1")
42 | androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
43 | }
44 |
45 | jsonSchema2Pojo {
46 | executions {
47 | create("main") {
48 | io {
49 | source.setFrom(files("${project.rootDir}/schema"))
50 | sourceType.set("jsonschema")
51 | outputEncoding.set("UTF-8")
52 | delimitersPropertyWord.set("")
53 | }
54 |
55 | klass {
56 | targetPackage.set("com.oosocial.clarityn.rest.clarityn.model")
57 | annotationStyle.set("gson")
58 | customAnnotatorClass.set("org.jsonschema2pojo.NoopAnnotator")
59 | }
60 |
61 | methods {
62 | builders.set(false)
63 | hashcodeAndEquals.set(true)
64 | toStringMethod.set(true)
65 | }
66 |
67 | fields {
68 | usePrimitives.set(false)
69 | integerUseLong.set(false)
70 | floatUseDouble.set(true)
71 | initializeCollections.set(true)
72 | }
73 |
74 | dateTime.jodaDate.set(false)
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib2/src/main/java/org/jsonschema2dataclass/lib/AndroidLibExample.java:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.lib;
2 |
3 | import com.oosocial.clarityn.rest.clarityn.model.EntrySchema;
4 | import com.oosocial.clarityn.rest.clarityn.model.Storage;
5 |
6 | public final class AndroidLibExample {
7 |
8 | public static void example() {
9 | EntrySchema schema = new EntrySchema();
10 | schema.setReadonly(false);
11 | schema.setFstype(EntrySchema.Fstype.EXT_4);
12 | schema.setStorage(new Storage());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/demo/android-agp7/lib2/src/main/resources/json/entry.schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-04/schema#",
3 | "definitions": {
4 | "diskDevice": {
5 | "additionalProperties": false,
6 | "properties": {
7 | "device": {
8 | "pattern": "^/dev/[^/]+(/[^/]+)*$",
9 | "type": "string"
10 | },
11 | "type": {
12 | "enum": [
13 | "disk"
14 | ]
15 | }
16 | },
17 | "required": [
18 | "type",
19 | "device"
20 | ]
21 | },
22 | "diskUUID": {
23 | "additionalProperties": false,
24 | "properties": {
25 | "label": {
26 | "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
27 | "type": "string"
28 | },
29 | "type": {
30 | "enum": [
31 | "disk"
32 | ]
33 | }
34 | },
35 | "required": [
36 | "type",
37 | "label"
38 | ]
39 | },
40 | "nfs": {
41 | "additionalProperties": false,
42 | "properties": {
43 | "remotePath": {
44 | "pattern": "^(/[^/]+)+$",
45 | "type": "string"
46 | },
47 | "server": {
48 | "oneOf": [
49 | {
50 | "format": "host-name"
51 | },
52 | {
53 | "format": "ipv4"
54 | },
55 | {
56 | "format": "ipv6"
57 | }
58 | ],
59 | "type": "string"
60 | },
61 | "type": {
62 | "enum": [
63 | "nfs"
64 | ]
65 | }
66 | },
67 | "required": [
68 | "type",
69 | "server",
70 | "remotePath"
71 | ]
72 | },
73 | "tmpfs": {
74 | "additionalProperties": false,
75 | "properties": {
76 | "sizeInMB": {
77 | "maximum": 512,
78 | "minimum": 16,
79 | "type": "integer"
80 | },
81 | "type": {
82 | "enum": [
83 | "tmpfs"
84 | ]
85 | }
86 | },
87 | "required": [
88 | "type",
89 | "sizeInMB"
90 | ]
91 | }
92 | },
93 | "description": "schema for an fstab entry",
94 | "id": "http://some.site.somewhere/entry-schema#",
95 | "properties": {
96 | "fstype": {
97 | "enum": [
98 | "ext3",
99 | "ext4",
100 | "btrfs"
101 | ]
102 | },
103 | "options": {
104 | "items": {
105 | "type": "string"
106 | },
107 | "minItems": 1,
108 | "type": "array",
109 | "uniqueItems": true
110 | },
111 | "readonly": {
112 | "type": "boolean"
113 | },
114 | "storage": {
115 | "oneOf": [
116 | {
117 | "$ref": "#/definitions/diskDevice"
118 | },
119 | {
120 | "$ref": "#/definitions/diskUUID"
121 | },
122 | {
123 | "$ref": "#/definitions/nfs"
124 | },
125 | {
126 | "$ref": "#/definitions/tmpfs"
127 | }
128 | ],
129 | "type": "object"
130 | }
131 | },
132 | "required": [
133 | "storage"
134 | ],
135 | "type": "object"
136 | }
137 |
--------------------------------------------------------------------------------
/demo/android-agp7/schema/entry.schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-04/schema#",
3 | "definitions": {
4 | "diskDevice": {
5 | "additionalProperties": false,
6 | "properties": {
7 | "device": {
8 | "pattern": "^/dev/[^/]+(/[^/]+)*$",
9 | "type": "string"
10 | },
11 | "type": {
12 | "enum": [
13 | "disk"
14 | ]
15 | }
16 | },
17 | "required": [
18 | "type",
19 | "device"
20 | ]
21 | },
22 | "diskUUID": {
23 | "additionalProperties": false,
24 | "properties": {
25 | "label": {
26 | "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
27 | "type": "string"
28 | },
29 | "type": {
30 | "enum": [
31 | "disk"
32 | ]
33 | }
34 | },
35 | "required": [
36 | "type",
37 | "label"
38 | ]
39 | },
40 | "nfs": {
41 | "additionalProperties": false,
42 | "properties": {
43 | "remotePath": {
44 | "pattern": "^(/[^/]+)+$",
45 | "type": "string"
46 | },
47 | "server": {
48 | "oneOf": [
49 | {
50 | "format": "host-name"
51 | },
52 | {
53 | "format": "ipv4"
54 | },
55 | {
56 | "format": "ipv6"
57 | }
58 | ],
59 | "type": "string"
60 | },
61 | "type": {
62 | "enum": [
63 | "nfs"
64 | ]
65 | }
66 | },
67 | "required": [
68 | "type",
69 | "server",
70 | "remotePath"
71 | ]
72 | },
73 | "tmpfs": {
74 | "additionalProperties": false,
75 | "properties": {
76 | "sizeInMB": {
77 | "maximum": 512,
78 | "minimum": 16,
79 | "type": "integer"
80 | },
81 | "type": {
82 | "enum": [
83 | "tmpfs"
84 | ]
85 | }
86 | },
87 | "required": [
88 | "type",
89 | "sizeInMB"
90 | ]
91 | }
92 | },
93 | "description": "schema for an fstab entry",
94 | "id": "http://some.site.somewhere/entry-schema#",
95 | "properties": {
96 | "fstype": {
97 | "enum": [
98 | "ext3",
99 | "ext4",
100 | "btrfs"
101 | ]
102 | },
103 | "options": {
104 | "items": {
105 | "type": "string"
106 | },
107 | "minItems": 1,
108 | "type": "array",
109 | "uniqueItems": true
110 | },
111 | "readonly": {
112 | "type": "boolean"
113 | },
114 | "storage": {
115 | "oneOf": [
116 | {
117 | "$ref": "#/definitions/diskDevice"
118 | },
119 | {
120 | "$ref": "#/definitions/diskUUID"
121 | },
122 | {
123 | "$ref": "#/definitions/nfs"
124 | },
125 | {
126 | "$ref": "#/definitions/tmpfs"
127 | }
128 | ],
129 | "type": "object"
130 | }
131 | },
132 | "required": [
133 | "storage"
134 | ],
135 | "type": "object"
136 | }
137 |
--------------------------------------------------------------------------------
/demo/android-agp7/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "Jsonschema2dataclass Android AGP7 sample"
2 |
3 | include ':app'
4 | include ':lib'
5 | include ':lib2'
6 |
--------------------------------------------------------------------------------
/demo/java/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.jsonschema2dataclass") version "6.0.0" apply false
3 | }
4 |
5 | subprojects {
6 | if (project.plugins.hasPlugin("java")) {
7 | project.extensions.configure {
8 | toolchain.languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion.toInt()))
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory-apply/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-library`
3 | id("org.jsonschema2dataclass")
4 | }
5 |
6 | dependencies {
7 | jsonschema2dataclassPlugins(project(":classpath:custom-rule-factory"))
8 |
9 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
10 | }
11 |
12 | jsonSchema2Pojo {
13 | executions {
14 | create("main") {
15 | klass.customRuleFactoryClass.set("org.jsonschema2dataclass.example.CustomRuleFactory")
16 | klass.annotationStyle.set("jackson2")
17 | klass.targetPackage.set("org.test")
18 | klass.nameUseTitle.set(true)
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory-apply/gradle.properties:
--------------------------------------------------------------------------------
1 | #systemProp.sonar.host.url="http://skat-sonarqube-osm2-sonarqube.ocpt.ccta.dk"
2 | ##org.gradle.daemon=false
3 | #org.gradle.parallel=true
4 | #org.gradle.configureondemand=false
5 | #org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
6 | #org.gradle.caching=true
7 | #
8 | #dockerRepository=osm2-docker-snapshot-local.artifactory.ccta.dk/osm2
9 | #
10 | #systemProp.file.encoding=utf-8
11 | #org.gradle.console=plain
12 | #
13 | #runServiceTests=false
14 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory-apply/src/main/resources/json/custom-factory.json:
--------------------------------------------------------------------------------
1 | {
2 | "properties": {
3 | "base64-field": {
4 | "format": "base64",
5 | "type": "string"
6 | }
7 | },
8 | "type": "object"
9 | }
10 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-library`
3 | }
4 |
5 | dependencies {
6 | compileOnly("org.jsonschema2pojo:jsonschema2pojo-core:1.2.2")
7 | }
8 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory/src/main/java/org/jsonschema2dataclass/example/CustomFormatRule.java:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.example;
2 |
3 | import com.fasterxml.jackson.databind.JsonNode;
4 | import com.sun.codemodel.JType;
5 | import java.util.Base64;
6 | import org.jsonschema2pojo.Schema;
7 | import org.jsonschema2pojo.rules.FormatRule;
8 | import org.jsonschema2pojo.rules.RuleFactory;
9 |
10 | public class CustomFormatRule extends FormatRule {
11 |
12 | protected CustomFormatRule(RuleFactory ruleFactory) {
13 | super(ruleFactory);
14 | }
15 |
16 | @Override
17 | public JType apply(String nodeName, JsonNode node, JsonNode parent, JType baseType, Schema schema) {
18 | if ("base64".equals(node.asText())) {
19 | return baseType.owner()._ref(Base64.class);
20 | } else {
21 | return super.apply(nodeName, node, parent, baseType, schema);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/demo/java/classpath/custom-rule-factory/src/main/java/org/jsonschema2dataclass/example/CustomRuleFactory.java:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.example;
2 |
3 | import com.sun.codemodel.JType;
4 | import org.jsonschema2pojo.Annotator;
5 | import org.jsonschema2pojo.GenerationConfig;
6 | import org.jsonschema2pojo.SchemaStore;
7 | import org.jsonschema2pojo.rules.Rule;
8 | import org.jsonschema2pojo.rules.RuleFactory;
9 |
10 | public class CustomRuleFactory extends RuleFactory {
11 | public CustomRuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) {
12 | super(generationConfig, annotator, schemaStore);
13 | }
14 |
15 | public CustomRuleFactory() {}
16 |
17 | public Rule getFormatRule() {
18 | return new CustomFormatRule(this);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/demo/java/classpath/schema-reference/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-library`
3 | id("org.jsonschema2dataclass")
4 | }
5 |
6 | dependencies {
7 | jsonschema2dataclassPlugins(project(":classpath:schema"))
8 |
9 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
10 | }
11 |
12 | jsonSchema2Pojo {
13 | executions {
14 | create("main") {
15 | io.source.setFrom(files("src/main/resources/schema/foo.json"))
16 | klass.annotationStyle.set("jackson2")
17 | klass.annotateGenerated.set(false)
18 | klass.targetPackage.set("org.test")
19 | klass.nameUseTitle.set(true)
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/demo/java/classpath/schema-reference/src/main/resources/schema/foo.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-07/schema#",
3 | "additionalProperties": false,
4 | "properties": {
5 | "metadata": {
6 | "$ref": "classpath:/schema/bar.json#",
7 | "existingJavaType": "com.examples.types.Metadata"
8 | },
9 | "name": {
10 | "type": "string"
11 | }
12 | },
13 | "title": "Foo",
14 | "type": "object"
15 | }
16 |
--------------------------------------------------------------------------------
/demo/java/classpath/schema/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-library`
3 | }
4 |
5 | tasks.named("jar") {
6 | enabled = true
7 | }
8 |
--------------------------------------------------------------------------------
/demo/java/classpath/schema/src/main/resources/schema/bar.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-07/schema#",
3 | "additionalProperties": false,
4 | "properties": {
5 | "id": {
6 | "type": "string"
7 | },
8 | "name": {
9 | "type": "string"
10 | }
11 | },
12 | "title": "Metadata",
13 | "type": "object"
14 | }
15 |
--------------------------------------------------------------------------------
/demo/java/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
2 | org.gradle.warning.mode=all
3 | org.gradle.priority=low
4 |
--------------------------------------------------------------------------------
/demo/java/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/demo/java/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/demo/java/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/demo/java/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/demo/java/groovy/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.jsonschema2dataclass'
4 | }
5 |
6 | dependencies {
7 | implementation 'javax.validation:validation-api:2.0.1.Final'
8 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.19.0'
9 |
10 | // see src/main/resources/json/external_dependencies.json
11 | implementation 'joda-time:joda-time:2.14.0'
12 | }
13 |
14 | jsonSchema2Pojo {
15 | executions{
16 | main {
17 | io.delimitersPropertyWord = '_'
18 | io.source.setFrom files("${projectDir}/src/main/resources/json")
19 | klass.annotateGenerated = false
20 | klass.targetPackage = 'example'
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/demo/java/groovy/src/main/java/org/js2d/AddressWork.java:
--------------------------------------------------------------------------------
1 | package org.js2d;
2 |
3 | import example.Address;
4 |
5 | public class AddressWork {
6 | public void work() {
7 | Address address = new Address();
8 | address.setRegion("Region");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/demo/java/groovy/src/main/resources/json/address.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "extended_address": "street_address",
4 | "post_office_box": "street_address"
5 | },
6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard",
7 | "properties": {
8 | "address": {
9 | "items": "string",
10 | "type": "array"
11 | },
12 | "country_name": {
13 | "required": true,
14 | "type": "string"
15 | },
16 | "extended_address": {
17 | "type": "string"
18 | },
19 | "locality": {
20 | "required": true,
21 | "type": "string"
22 | },
23 | "post_office_box": {
24 | "type": "string"
25 | },
26 | "postal_code": {
27 | "type": "string"
28 | },
29 | "region": {
30 | "required": true,
31 | "type": "string"
32 | },
33 | "street_address": {
34 | "type": "string"
35 | }
36 | },
37 | "type": "object"
38 | }
39 |
--------------------------------------------------------------------------------
/demo/java/groovy/src/main/resources/json/external_dependencies.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "An example on how to reference pre-existing classes",
3 | "properties": {
4 | "a_joda_time_object": {
5 | "existingJavaType": "org.joda.time.DateTime",
6 | "type": "object"
7 | }
8 | },
9 | "type": "object"
10 | }
11 |
--------------------------------------------------------------------------------
/demo/java/kotlin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm") version "2.1.20"
3 | id("org.jsonschema2dataclass")
4 | }
5 |
6 | tasks.withType().all {
7 | kotlinOptions {
8 | jvmTarget = JavaVersion.current().toString()
9 | }
10 | }
11 | dependencies {
12 | implementation("javax.validation:validation-api:2.0.1.Final")
13 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
14 |
15 | // see src/main/resources/json/external_dependencies.json
16 | implementation("joda-time:joda-time:2.14.0")
17 | }
18 |
19 | jsonSchema2Pojo {
20 | executions {
21 | create("main") {
22 | io.delimitersPropertyWord.set("_")
23 | io.source.setFrom(files("$projectDir/src/main/resources/json"))
24 | klass.annotateGenerated.set(false)
25 | klass.targetPackage.set("example")
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/demo/java/kotlin/src/main/kotlin/org/js2d/AddressWork.kt:
--------------------------------------------------------------------------------
1 | import example.Address
2 |
3 | class AddressWork {
4 | fun work() {
5 | val address = Address()
6 | address.setRegion("Region")
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/demo/java/kotlin/src/main/resources/json/address.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "extended_address": "street_address",
4 | "post_office_box": "street_address"
5 | },
6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard",
7 | "properties": {
8 | "address": {
9 | "items": "string",
10 | "type": "array"
11 | },
12 | "country_name": {
13 | "required": true,
14 | "type": "string"
15 | },
16 | "extended_address": {
17 | "type": "string"
18 | },
19 | "locality": {
20 | "required": true,
21 | "type": "string"
22 | },
23 | "post_office_box": {
24 | "type": "string"
25 | },
26 | "postal_code": {
27 | "type": "string"
28 | },
29 | "region": {
30 | "required": true,
31 | "type": "string"
32 | },
33 | "street_address": {
34 | "type": "string"
35 | }
36 | },
37 | "type": "object"
38 | }
39 |
--------------------------------------------------------------------------------
/demo/java/kotlin/src/main/resources/json/external_dependencies.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "An example on how to reference pre-existing classes",
3 | "properties": {
4 | "a_joda_time_object": {
5 | "existingJavaType": "org.joda.time.DateTime",
6 | "type": "object"
7 | }
8 | },
9 | "type": "object"
10 | }
11 |
--------------------------------------------------------------------------------
/demo/java/model-publish/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `maven-publish`
3 | kotlin("jvm") version "2.1.20"
4 | id("org.jsonschema2dataclass")
5 | }
6 |
7 | project.group = "com.example"
8 | project.version = "1.0"
9 |
10 | val targetJSONBaseDir = files("$projectDir/src/main/resources/json")
11 |
12 | dependencies {
13 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
14 |
15 | // see src/main/resources/json/external_dependencies.json
16 | implementation("joda-time:joda-time:2.14.0")
17 | }
18 |
19 | val sourceJar = tasks.create("sourceJar") {
20 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE
21 | from(sourceSets.main.get().allJava)
22 | archiveClassifier.set("sources")
23 | dependsOn("build")
24 | }
25 |
26 | val schemasJar = tasks.create("schemasJar") {
27 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE
28 | from(targetJSONBaseDir)
29 | archiveClassifier.set("schemas")
30 | dependsOn("build")
31 | }
32 |
33 | publishing {
34 | publications {
35 | create("modulePublish") {
36 | artifact(tasks.named("jar"))
37 | artifact(sourceJar)
38 | artifact(schemasJar)
39 | artifactId = "models"
40 | }
41 | }
42 | }
43 |
44 | jsonSchema2Pojo {
45 | executions {
46 | create("main") {
47 | io.source.setFrom(targetJSONBaseDir)
48 | klass.annotateGenerated.set(false)
49 | klass.targetPackage.set(project.group.toString())
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/demo/java/model-publish/src/main/resources/json/address.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "extended_address": "street_address",
4 | "post_office_box": "street_address"
5 | },
6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard",
7 | "properties": {
8 | "address": {
9 | "items": "string",
10 | "type": "array"
11 | },
12 | "country_name": {
13 | "required": true,
14 | "type": "string"
15 | },
16 | "extended_address": {
17 | "type": "string"
18 | },
19 | "locality": {
20 | "required": true,
21 | "type": "string"
22 | },
23 | "post_office_box": {
24 | "type": "string"
25 | },
26 | "postal_code": {
27 | "type": "string"
28 | },
29 | "region": {
30 | "required": true,
31 | "type": "string"
32 | },
33 | "street_address": {
34 | "type": "string"
35 | }
36 | },
37 | "type": "object"
38 | }
39 |
--------------------------------------------------------------------------------
/demo/java/model-publish/src/main/resources/json/external_dependencies.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "An example on how to reference pre-existing classes",
3 | "properties": {
4 | "a_joda_time_object": {
5 | "existingJavaType": "org.joda.time.DateTime",
6 | "type": "object"
7 | }
8 | },
9 | "type": "object"
10 | }
11 |
--------------------------------------------------------------------------------
/demo/java/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "Json Schema 2 Data Class Java demos"
2 |
3 | // Groovy DSL & Groovy language
4 | include(":groovy")
5 | // Kotlin DSL & Kotlin language
6 | include(":kotlin")
7 | // Example, how to publish models and schemas
8 | include(":model-publish")
9 | // schema for schema-reference example
10 | include(":classpath:schema")
11 | // Use schemas from classpath
12 | include(":classpath:schema-reference")
13 | // Custom rule factory
14 | include(":classpath:custom-rule-factory")
15 | // How to apply custom rule factory
16 | include(":classpath:custom-rule-factory-apply")
17 |
18 | @Suppress("UnstableApiUsage")
19 | dependencyResolutionManagement {
20 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
21 | repositories {
22 | mavenCentral()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/docs/migration/migration.adoc:
--------------------------------------------------------------------------------
1 | = Migration guide list
2 |
3 | * xref:migration_5.adoc[Migration from 4.x and below to 5.0]
4 | * xref:migration_6.adoc[Migration from 5.x to 6.0]
5 |
--------------------------------------------------------------------------------
/docs/migration/migration_5.adoc:
--------------------------------------------------------------------------------
1 | :toc:
2 | :toc-placement: preamble
3 | :toclevels: 2
4 | :showtitle:
5 |
6 | = Migration guide from 4.5.0 to 5.0
7 |
8 | This guide highlights major changes and shows how to change a project to use new plugin.
9 |
10 | == Default execution is deprecated and removed
11 |
12 | Previously, it was possible to define execution without an execution.
13 | Now it's important to define executions for every single project.
14 |
15 | Improperly upgraded projects using the old model will receive a warning
16 | during the build briefly explaining actions required.
17 |
18 | The reasons of deprecation and removal of this feature is:
19 |
20 | * There's no way to tell how and if extension has been applied.
21 | * Plugin features can't be extended as much as they planned.
22 | * Configuration refactoring can't be done as easy as it could be.
23 | * A lot of spaghetti, generated and copy-paste code in the plugin makes it hard to maintain and catch an error.
24 |
25 | Examples:
26 |
27 | .No Extension defined example
28 | [options=header,cols="1,5"]
29 | |=====
30 | | DSL language | DSL
31 | // ------------------------------
32 | | Groovy
33 |
34 | Old version (prior 5.x),
35 | a|
36 | [source,gradle]
37 | -----
38 | plugins {
39 | id "java"
40 | id "org.jsonschema2dataclass" version "x.y.z"
41 | }
42 | -----
43 | // ------------------------------
44 | | Groovy
45 |
46 | Recommended new version (5.x)
47 | a|
48 | [source,gradle]
49 | -----
50 | plugins {
51 | id "java"
52 | id "org.jsonschema2dataclass" version "x.y.z"
53 | }
54 |
55 | jsonSchema2Pojo {
56 | executions {
57 | main {}
58 | }
59 | }
60 | -----
61 | // ------------------------------
62 | | Kotlin
63 |
64 | Old version (prior 5.x),
65 | a|
66 | [source,gradle]
67 | -----
68 | plugins {
69 | `java`
70 | id("org.jsonschema2dataclass") version "x.y.z"
71 | }
72 | -----
73 | // ------------------------------
74 | | Kotlin
75 |
76 | Recommended new version (5.x)
77 | a|
78 | [source,gradle]
79 | -----
80 | plugins {
81 | `java`
82 | id("org.jsonschema2dataclass") version "x.y.z"
83 | }
84 |
85 | jsonSchema2Pojo {
86 | executions {
87 | create("main")
88 | }
89 | }
90 | -----
91 | // ------------------------------
92 | |=====
93 |
94 | .No execution defined in extension
95 | [options=header,cols="1,5"]
96 | |=====
97 | | DSL language | DSL
98 | // ------------------------------
99 | | Groovy
100 |
101 | Old version (prior 5.x),
102 | a|
103 | [source,gradle]
104 | -----
105 | plugins {
106 | id "java"
107 | id "org.jsonschema2dataclass" version "x.y.z"
108 | }
109 |
110 | jsonSchema2Pojo {
111 | targetPackage = 'example'
112 | }
113 | -----
114 | // ------------------------------
115 | | Groovy
116 |
117 | Recommended new version (5.x)
118 | a|
119 | [source,gradle]
120 | -----
121 | plugins {
122 | id "java"
123 | id "org.jsonschema2dataclass" version "x.y.z"
124 | }
125 |
126 | jsonSchema2Pojo {
127 | executions {
128 | main {
129 | targetPackage = 'example'
130 | }
131 | }
132 | }
133 | -----
134 | // ------------------------------
135 | | Kotlin
136 |
137 | Old version (prior 5.x),
138 | a|
139 | [source,gradle]
140 | -----
141 | plugins {
142 | `java`
143 | id("org.jsonschema2dataclass") version "x.y.z"
144 | }
145 | jsonSchema2Pojo {
146 | targetPackage.set("example")
147 | }
148 | -----
149 | // ------------------------------
150 | | Kotlin
151 |
152 | Recommended new version (5.x)
153 | a|
154 | [source,gradle]
155 | -----
156 | plugins {
157 | `java`
158 | id("org.jsonschema2dataclass") version "x.y.z"
159 | }
160 |
161 | jsonSchema2Pojo {
162 | executions {
163 | create("main") {
164 | targetPackage.set("example")
165 | }
166 | }
167 | }
168 | -----
169 | // ------------------------------
170 | |=====
171 |
172 | == Subtasks changed their names
173 |
174 | Version 5.0 renames sub-tasks to more readable values. Main tasks still have the same name as before.
175 |
176 | . Configuration name is used as part of task name instead of a sequence number.
177 | * Gradle API provides a set of configurations instead of list and never guarantees, which configuration will be first.
178 | * Using configuration names is more readable when a developer refers to it.
179 | . Android variant part is shifted toward beginning.
180 | * This way it's easier to read task list.
181 |
182 | [options=header]
183 | |=====
184 | | Old name | New name | Notes
185 | // ------------------------------
186 | | generateJsonSchema2DataClass0
187 | | generateJsonSchema2DataClassConfigMain
188 | | Configuration name at the end
189 | // ------------------------------
190 | | generateJsonSchema2DataClassForRelease
191 | | generateJsonSchema2DataClassForRelease
192 | | Common task with Android variant is the same
193 | // ------------------------------
194 | | generateJsonSchema2DataClass0ForRelease
195 | | generateJsonSchema2DataClassForReleaseConfigMain
196 | | Android variant part shifted
197 | // ------------------------------
198 | |=====
199 |
200 | == Ability to hook for any task in gradle scripts and other plugins
201 |
202 | From 5.x onwards the plugin applies itself and generate tasks as soon as possible.
203 | Thus, it's possible to directly hook the tasks if needed.
204 |
205 | Previously, it was possible create only indirect hooks for tasks (which is still the preferred way to hook):
206 | * generateJsonSchema2DataClass depends on resource processing tasks
207 | * compilation and Lombok plugin tasks depend on generateJsonSchema2DataClass
208 |
209 | == AGP 3 demo is removed, AGP 4 demo is unmaintained.
210 |
211 | I have no machine to build the demo. It requires build tools `30.0.3` at the most and can't use newer ones.
212 | Google provides binaries incompatible with my computer and CPU architecture.
213 |
214 | Additionally, I was unable to find live Android library or application projects on GitHub.
215 |
216 | This project is using and maintaining AGP3 API and will abandon it when Google decides to remove support of it.
217 |
218 | === AGP 3 demo is removed
219 |
220 | It doesn't build on CI for a little while and I can't build on my computer as well.
221 |
222 | === AGP 4 demo is unmaintained
223 |
224 | Mostly because of lack of build tools on my computer.
225 |
--------------------------------------------------------------------------------
/docs/usage/basic.adoc:
--------------------------------------------------------------------------------
1 | :toc:
2 | :toc-placement: preamble
3 | :toclevels: 2
4 | :showtitle:
5 |
6 | = Basic plugin usage and support
7 |
8 | This page shows plugin basic usage and support.
9 |
10 | == Apply the plugin and basic settings
11 |
12 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
13 |
14 | Then it's required to specify execution and their settings in the extension.
15 |
16 | The minimal usage example looks like shown in the following table.
17 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration.
18 |
19 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work.
20 |
21 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen.
22 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly.
23 | Execution section might contain as many executions as project needs (at least 1).
24 |
25 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section.
26 |
27 | [options=header,cols="1,5"]
28 | |=====
29 | | DSL language | DSL
30 | // ------------------------------
31 | | Groovy
32 | a|
33 | [source,gradle]
34 | -----
35 | plugins {
36 | id "java"
37 | id "org.jsonschema2dataclass" version "x.y.z"
38 | }
39 |
40 | jsonSchema2Pojo {
41 | executions {
42 | main {}
43 | }
44 | }
45 | -----
46 | // ------------------------------
47 | | Kotlin
48 | a|
49 | [source,gradle]
50 | -----
51 | plugins {
52 | `java`
53 | id("org.jsonschema2dataclass") version "x.y.z"
54 | }
55 |
56 | jsonSchema2Pojo {
57 | executions {
58 | create("main") {
59 | }
60 | }
61 | }
62 | -----
63 | // ------------------------------
64 | |=====
65 |
66 | == SDK and build tools support
67 |
68 | .Demos and statuses
69 | [options=header]
70 | |=====
71 | | SDK/Tool | Minimal Version | Maximum version | Notes
72 | // ------------------------------
73 | | Java compiler
74 | | 8
75 | | 19
76 | |
77 | // ------------------------------
78 | | Gradle
79 | | 6.0
80 | | 7.x
81 | | 8.0 support is beta till it will be released
82 | // ------------------------------
83 | | Android Gradle Plugin
84 | | 3
85 | | 7
86 | |
87 | // ------------------------------
88 | |=====
89 |
90 | == Demos and their statuses
91 |
92 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
93 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin.
94 |
95 | Also, there's also integration tests which are
96 |
97 | Any contributions are welcome.
98 |
99 | .Demos and statuses
100 | [options=header]
101 | |=====
102 | | Platform | Demo | Status | Notes
103 | // ------------------------------
104 | .3+| JVM
105 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
106 | | Maintained and healthy
107 | |
108 | // ------------------------------
109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
110 | | Maintained and healthy
111 | |
112 | // ------------------------------
113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
114 | | Maintained and healthy
115 | |
116 | // ------------------------------
117 | .4+| Android
118 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example
119 | | Maintained and healthy
120 | |
121 | // ------------------------------
122 | | AGP 8
123 | | Waiting for releases from Google and Gradle
124 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation
125 | // ------------------------------
126 | | AGP 4
127 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0
128 | | Was unmaintained for a while
129 | // ------------------------------
130 | | AGP 3
131 | | ⚠️ Demo has been removed in 5.0
132 | | Was unmaintained for a while
133 | // ------------------------------
134 | |=====
135 |
136 | For AGP 3 and AGP 4 I have no computer to build the demos.
137 |
--------------------------------------------------------------------------------
/docs/usage/basic_2.adoc:
--------------------------------------------------------------------------------
1 | :plugin_major: 5
2 | :demo-agp4: was marked as unmaintained
3 |
4 | :toc:
5 | :toc-placement: preamble
6 | :toclevels: 2
7 | :showtitle:
8 |
9 | = Basic plugin usage and support
10 |
11 | This page shows plugin basic usage and support.
12 |
13 | == Apply the plugin and basic settings
14 |
15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
16 |
17 | Then it's required to specify execution and their settings in the extension.
18 |
19 | The minimal usage example looks like shown in the following table.
20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration.
21 |
22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work.
23 | Kotlin and Groovy automatically apply one of plugin mentioned before.
24 |
25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen.
26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly.
27 | Execution section might contain as many executions as project needs (at least 1).
28 |
29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section.
30 |
31 | [options=header,cols="1,5"]
32 | |=====
33 | | DSL language | DSL
34 | // ------------------------------
35 | | Groovy
36 | a|
37 | [source,gradle]
38 | -----
39 | plugins {
40 | id "java"
41 | id "org.jsonschema2dataclass" version "x.y.z"
42 | }
43 |
44 | jsonSchema2Pojo {
45 | executions {
46 | main {}
47 | }
48 | }
49 | -----
50 | // ------------------------------
51 | | Kotlin
52 | a|
53 | [source,gradle]
54 | -----
55 | plugins {
56 | `java`
57 | id("org.jsonschema2dataclass") version "x.y.z"
58 | }
59 |
60 | jsonSchema2Pojo {
61 | executions {
62 | create("main") {
63 | }
64 | }
65 | }
66 | -----
67 | // ------------------------------
68 | |=====
69 |
70 | == SDK and build tools support
71 |
72 | .Demos and statuses
73 | [options=header]
74 | |=====
75 | | SDK/Tool | Minimal Version | Maximum version | Notes
76 | // ------------------------------
77 | | Java compiler
78 | | 8
79 | | 19
80 | |
81 | // ------------------------------
82 | | Gradle
83 | | 6.0
84 | | 7.x
85 | | 8.0 support is beta till it will be released
86 | // ------------------------------
87 | | Android Gradle Plugin
88 | | 3
89 | | 7
90 | |
91 | // ------------------------------
92 | |=====
93 |
94 | == Demos and their statuses
95 |
96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin.
98 |
99 | Also, there's also integration tests which are
100 |
101 | Any contributions are welcome.
102 |
103 | .Demos and statuses
104 | [options=header]
105 | |=====
106 | | Platform | Demo | Status | Notes
107 | // ------------------------------
108 | .3+| JVM
109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
110 | | Maintained and healthy
111 | |
112 | // ------------------------------
113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
114 | | Maintained and healthy
115 | |
116 | // ------------------------------
117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
118 | | Maintained and healthy
119 | |
120 | // ------------------------------
121 | .4+| Android
122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example
123 | | Maintained and healthy
124 | |
125 | // ------------------------------
126 | | AGP 8
127 | | Waiting for releases from Google and Gradle
128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation
129 | // ------------------------------
130 | | AGP 4
131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0
132 | | Was unmaintained for a while
133 | // ------------------------------
134 | | AGP 3
135 | | ⚠️ Demo has been removed in 5.0
136 | | Was unmaintained for a while
137 | // ------------------------------
138 | |=====
139 |
140 | For AGP 3 and AGP 4 I have no computer to build the demos.
141 |
--------------------------------------------------------------------------------
/docs/usage/basic_3.adoc:
--------------------------------------------------------------------------------
1 | :plugin_major: 5
2 | :demo-agp4: was marked as unmaintained
3 |
4 | :toc:
5 | :toc-placement: preamble
6 | :toclevels: 2
7 | :showtitle:
8 |
9 | = Basic plugin usage and support
10 |
11 | This page shows plugin basic usage and support.
12 |
13 | == Apply the plugin and basic settings
14 |
15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
16 |
17 | Then it's required to specify execution and their settings in the extension.
18 |
19 | The minimal usage example looks like shown in the following table.
20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration.
21 |
22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work.
23 | Kotlin and Groovy automatically apply one of plugin mentioned before.
24 |
25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen.
26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly.
27 | Execution section might contain as many executions as project needs (at least 1).
28 |
29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section.
30 |
31 | [options=header,cols="1,5"]
32 | |=====
33 | | DSL language | DSL
34 | // ------------------------------
35 | | Groovy
36 | a|
37 | [source,gradle]
38 | -----
39 | plugins {
40 | id "java"
41 | id "org.jsonschema2dataclass" version "x.y.z"
42 | }
43 |
44 | jsonSchema2Pojo {
45 | executions {
46 | main {}
47 | }
48 | }
49 | -----
50 | // ------------------------------
51 | | Kotlin
52 | a|
53 | [source,gradle]
54 | -----
55 | plugins {
56 | `java`
57 | id("org.jsonschema2dataclass") version "x.y.z"
58 | }
59 |
60 | jsonSchema2Pojo {
61 | executions {
62 | create("main") {
63 | }
64 | }
65 | }
66 | -----
67 | // ------------------------------
68 | |=====
69 |
70 | == SDK and build tools support
71 |
72 | .Demos and statuses
73 | [options=header]
74 | |=====
75 | | SDK/Tool | Minimal Version | Maximum version | Notes
76 | // ------------------------------
77 | | Java compiler
78 | | 8
79 | | 19
80 | |
81 | // ------------------------------
82 | | Gradle
83 | | 6.0
84 | | 7.x
85 | | 8.0 support is beta till it will be released
86 | // ------------------------------
87 | | Android Gradle Plugin
88 | | 3
89 | | 7
90 | |
91 | // ------------------------------
92 | |=====
93 |
94 | == Demos and their statuses
95 |
96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin.
98 |
99 | Also, there's also integration tests which are
100 |
101 | Any contributions are welcome.
102 |
103 | .Demos and statuses
104 | [options=header]
105 | |=====
106 | | Platform | Demo | Status | Notes
107 | // ------------------------------
108 | .3+| JVM
109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
110 | | Maintained and healthy
111 | |
112 | // ------------------------------
113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
114 | | Maintained and healthy
115 | |
116 | // ------------------------------
117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
118 | | Maintained and healthy
119 | |
120 | // ------------------------------
121 | .4+| Android
122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example
123 | | Maintained and healthy
124 | |
125 | // ------------------------------
126 | | AGP 8
127 | | Waiting for releases from Google and Gradle
128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation
129 | // ------------------------------
130 | | AGP 4
131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0
132 | | Was unmaintained for a while
133 | // ------------------------------
134 | | AGP 3
135 | | ⚠️ Demo has been removed in 5.0
136 | | Was unmaintained for a while
137 | // ------------------------------
138 | |=====
139 |
140 | For AGP 3 and AGP 4 I have no computer to build the demos.
141 |
--------------------------------------------------------------------------------
/docs/usage/basic_4.adoc:
--------------------------------------------------------------------------------
1 | :plugin_major: 5
2 | :demo-agp4: was marked as unmaintained
3 |
4 | :toc:
5 | :toc-placement: preamble
6 | :toclevels: 2
7 | :showtitle:
8 |
9 | = Basic plugin usage and support
10 |
11 | This page shows plugin basic usage and support.
12 |
13 | == Apply the plugin and basic settings
14 |
15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
16 |
17 | Then it's required to specify execution and their settings in the extension.
18 |
19 | The minimal usage example looks like shown in the following table.
20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration.
21 |
22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work.
23 | Kotlin and Groovy automatically apply one of plugin mentioned before.
24 |
25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen.
26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly.
27 | Execution section might contain as many executions as project needs (at least 1).
28 |
29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section.
30 |
31 | [options=header,cols="1,5"]
32 | |=====
33 | | DSL language | DSL
34 | // ------------------------------
35 | | Groovy
36 | a|
37 | [source,gradle]
38 | -----
39 | plugins {
40 | id "java"
41 | id "org.jsonschema2dataclass" version "x.y.z"
42 | }
43 |
44 | jsonSchema2Pojo {
45 | executions {
46 | main {}
47 | }
48 | }
49 | -----
50 | // ------------------------------
51 | | Kotlin
52 | a|
53 | [source,gradle]
54 | -----
55 | plugins {
56 | `java`
57 | id("org.jsonschema2dataclass") version "x.y.z"
58 | }
59 |
60 | jsonSchema2Pojo {
61 | executions {
62 | create("main") {
63 | }
64 | }
65 | }
66 | -----
67 | // ------------------------------
68 | |=====
69 |
70 | == SDK and build tools support
71 |
72 | .Demos and statuses
73 | [options=header]
74 | |=====
75 | | SDK/Tool | Minimal Version | Maximum version | Notes
76 | // ------------------------------
77 | | Java compiler
78 | | 8
79 | | 19
80 | |
81 | // ------------------------------
82 | | Gradle
83 | | 6.0
84 | | 7.x
85 | | 8.0 support is beta till it will be released
86 | // ------------------------------
87 | | Android Gradle Plugin
88 | | 3
89 | | 7
90 | |
91 | // ------------------------------
92 | |=====
93 |
94 | == Demos and their statuses
95 |
96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin.
98 |
99 | Also, there's also integration tests which are
100 |
101 | Any contributions are welcome.
102 |
103 | .Demos and statuses
104 | [options=header]
105 | |=====
106 | | Platform | Demo | Status | Notes
107 | // ------------------------------
108 | .3+| JVM
109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
110 | | Maintained and healthy
111 | |
112 | // ------------------------------
113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
114 | | Maintained and healthy
115 | |
116 | // ------------------------------
117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
118 | | Maintained and healthy
119 | |
120 | // ------------------------------
121 | .4+| Android
122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example
123 | | Maintained and healthy
124 | |
125 | // ------------------------------
126 | | AGP 8
127 | | Waiting for releases from Google and Gradle
128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation
129 | // ------------------------------
130 | | AGP 4
131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0
132 | | Was unmaintained for a while
133 | // ------------------------------
134 | | AGP 3
135 | | ⚠️ Demo has been removed in 5.0
136 | | Was unmaintained for a while
137 | // ------------------------------
138 | |=====
139 |
140 | For AGP 3 and AGP 4 I have no computer to build the demos.
141 |
--------------------------------------------------------------------------------
/docs/usage/basic_5.adoc:
--------------------------------------------------------------------------------
1 | :plugin_major: 5
2 | :demo-agp4: was marked as unmaintained
3 |
4 | :toc:
5 | :toc-placement: preamble
6 | :toclevels: 2
7 | :showtitle:
8 |
9 | = Basic plugin usage and support
10 |
11 | This page shows plugin basic usage and support.
12 |
13 | == Apply the plugin and basic settings
14 |
15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
16 |
17 | Then it's required to specify execution and their settings in the extension.
18 |
19 | The minimal usage example looks like shown in the following table.
20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration.
21 |
22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work.
23 | Kotlin and Groovy automatically apply one of plugin mentioned before.
24 |
25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen.
26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly.
27 | Execution section might contain as many executions as project needs (at least 1).
28 |
29 |
30 |
31 | [options=header,cols="1,5"]
32 | |=====
33 | | DSL language | DSL
34 | // ------------------------------
35 | | Groovy
36 | a|
37 | [source,gradle]
38 | -----
39 | plugins {
40 | id "java"
41 | id "org.jsonschema2dataclass" version "x.y.z"
42 | }
43 |
44 | jsonSchema2Pojo {
45 | executions {
46 | main {}
47 | }
48 | }
49 | -----
50 | // ------------------------------
51 | | Kotlin
52 | a|
53 | [source,gradle]
54 | -----
55 | plugins {
56 | `java`
57 | id("org.jsonschema2dataclass") version "x.y.z"
58 | }
59 |
60 | jsonSchema2Pojo {
61 | executions {
62 | create("main") {
63 | }
64 | }
65 | }
66 | -----
67 | // ------------------------------
68 | |=====
69 |
70 | == SDK and build tools support
71 |
72 | .Demos and statuses
73 | [options=header]
74 | |=====
75 | | SDK/Tool | Minimal Version | Maximum version | Notes
76 | // ------------------------------
77 | | Java compiler
78 | | 8
79 | | 19
80 | |
81 | // ------------------------------
82 | | Gradle
83 | | 6.0
84 | | 7.x
85 | | 8.0 support is beta till it will be released
86 | // ------------------------------
87 | | Android Gradle Plugin
88 | | 3
89 | | 7
90 | |
91 | // ------------------------------
92 | |=====
93 |
94 | == Demos and their statuses
95 |
96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin.
98 |
99 | Also, there's also integration tests which are
100 |
101 | Any contributions are welcome.
102 |
103 | .Demos and statuses
104 | [options=header]
105 | |=====
106 | | Platform | Demo | Status | Notes
107 | // ------------------------------
108 | .3+| JVM
109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
110 | | Maintained and healthy
111 | |
112 | // ------------------------------
113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
114 | | Maintained and healthy
115 | |
116 | // ------------------------------
117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
118 | | Maintained and healthy
119 | |
120 | // ------------------------------
121 | .4+| Android
122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example
123 | | Maintained and healthy
124 | |
125 | // ------------------------------
126 | | AGP 8
127 | | Waiting for releases from Google and Gradle
128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation
129 | // ------------------------------
130 | | AGP 4
131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0
132 | | Was unmaintained for a while
133 | // ------------------------------
134 | | AGP 3
135 | | ⚠️ Demo has been removed in 5.0
136 | | Was unmaintained for a while
137 | // ------------------------------
138 | |=====
139 |
140 | For AGP 3 and AGP 4 I have no computer to build the demos.
141 |
--------------------------------------------------------------------------------
/docs/usage/basic_6.adoc:
--------------------------------------------------------------------------------
1 | :plugin_major: 6
2 | :demo-agp4: has been removed
3 |
4 | :toc:
5 | :toc-placement: preamble
6 | :toclevels: 2
7 | :showtitle:
8 |
9 | = Basic plugin usage and support
10 |
11 | This page shows plugin basic usage and support.
12 |
13 | == Plugin requirements and compatibility
14 |
15 | Plugin requires to work one of these plugins: `java`, `java library`, `Android application` or `Android library`.
16 | These plugins can be applied directly or indirectly.
17 |
18 | Additionally, plugin is compatible with `org.freefair.lombok`.
19 |
20 | == Apply the plugin and basic settings
21 |
22 | One should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin.
23 |
24 | Examples are provided in a table below to showcase `org.jsonschema2dataclass` plugin minimal configuration.
25 | This way, extension `jsonSchema2Pojo` will be configured with an execution `example` in the `executions` container.
26 |
27 | More detailed usage is documented in xref:parameters_{plugin_major}.adoc[parameters] section.
28 |
29 | [options=header,cols="1,5"]
30 | |=====
31 | | DSL language | DSL example
32 | // ------------------------------
33 | | Groovy
34 | a|
35 | [source,groovy]
36 | -----
37 | plugins {
38 | id "java"
39 | id "org.jsonschema2dataclass" version "x.y.z"
40 | }
41 |
42 | jsonSchema2Pojo {
43 | executions {
44 | example {}
45 | }
46 | }
47 | -----
48 | // ------------------------------
49 | | Kotlin
50 | a|
51 | [source,kotlin]
52 | -----
53 | plugins {
54 | java
55 | id("org.jsonschema2dataclass") version "x.y.z"
56 | }
57 |
58 | jsonSchema2Pojo {
59 | executions {
60 | create("example") {
61 | }
62 | }
63 | }
64 | -----
65 | // ------------------------------
66 | |=====
67 |
68 | == Processor dependencies
69 |
70 | In some cases it is required to specify dependencies for a processor to
71 | reference some JSON files via classpath or define plugin classes for a processor.
72 |
73 | To achieve this, it is required to add these dependencies to `jsonschema2dataclassPlugins`
74 | https://docs.gradle.org/current/userguide/dependency_management_terminology.html#sub:terminology_configuration[configuration].
75 |
76 | NOTE: It's impossible to add a dependency from an output from an execution.
77 |
78 | == Hooks and task dependencies
79 |
80 | By default, plugin generates tasks to be run after process resources task, so the output from this task can be used.
81 | Additionally, plugin tasks are configured to run before execution of compilation
82 | and lombok (from `org.freefair.lombok`) processor.
83 |
84 | == SDK and build tools support
85 |
86 | .Demos and statuses
87 | [options=header]
88 | |=====
89 | | SDK/Tool | Minimal Version | Maximum version | Notes
90 | // ------------------------------
91 | | Java compiler
92 | | 8
93 | | 19
94 | |
95 | // ------------------------------
96 | | Gradle
97 | | 6.0
98 | | 7.x
99 | | 8.0 support is currently in beta.
100 | // ------------------------------
101 | | Android Gradle Plugin
102 | | 3
103 | | 7
104 | |
105 | // ------------------------------
106 | |=====
107 |
108 | == Demos and their statuses
109 |
110 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos].
111 | These minimal applications doesn't represent a normal full-featured applications for a given platform.
112 | These application are included for a showcase plugin features and capabilities.
113 |
114 | NOTE: Any additional ideas and contributions are welcome.
115 |
116 | .Demos and statuses
117 | [options=header]
118 | |=====
119 | | Platform | Demo | Status | Notes
120 | // ------------------------------
121 | .4+| JVM
122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example
123 | | Maintained and healthy
124 | | Demonstrates compatibility with Groovy DSL
125 | // ------------------------------
126 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example
127 | | Maintained and healthy
128 | | Demonstrates compatibility with Kotlin DSL and Kotlin language
129 | // ------------------------------
130 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example
131 | | Maintained and healthy
132 | | Demonstrates a way to publish jars with sources and schemas along with classes
133 | // ------------------------------
134 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/classpath[Plugin's processor classpath] examples
135 | | Maintained and healthy
136 | | Demonstrates usage for plugin's processor classpath manipulation to apply schemas and custom RuleFactory
137 | // ------------------------------
138 | .4+| Android
139 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android-agp7[AGP 7] example
140 | | Maintained and healthy
141 | | Demonstrates usage in an android application
142 | // ------------------------------
143 | | AGP 4
144 | | ⚠️ Demo has been removed since 6.0
145 | a|
146 |
147 | * AGP 4 API is used to bind to the Android project, so it's still technically supported.
148 | * PR and support for a demo is welcome
149 |
150 | // ------------------------------
151 | |=====
152 |
--------------------------------------------------------------------------------
/docs/usage/index.adoc:
--------------------------------------------------------------------------------
1 | = Plugin usage and parameters documentation
2 |
3 | == Version 4.x and below
4 |
5 | Version 4.x and below has mostly the same documentation as 5.x.
6 |
7 | == Version 5.x
8 |
9 | :plugin_major: 5
10 | * xref:basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x]
11 | * xref:parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x]
12 |
13 | == Version 6.x
14 |
15 | :plugin_major: 6
16 | * xref:basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x]
17 | * xref:parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x]
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
2 | org.gradle.warning.mode=all
3 | org.gradle.priority=low
4 |
--------------------------------------------------------------------------------
/gradle/agp.dependencies.toml:
--------------------------------------------------------------------------------
1 | [libraries]
2 | android-gradle-v4x = { module = "com.android.tools.build:gradle", version = "4.2.2" }
3 | android-gradle-v7x = { module = "com.android.tools.build:gradle", version = "7.4.2" }
4 |
--------------------------------------------------------------------------------
/gradle/init.gradle.kts:
--------------------------------------------------------------------------------
1 | gradle.settingsEvaluated {
2 | val localPublishExtra = "org.jsonschema2dataclass.internal.local-publish"
3 | val localVersionExtra = "org.jsonschema2dataclass.internal.git-version"
4 | if (extra.has(localPublishExtra) && extra[localPublishExtra].toString().toBoolean()) {
5 | val localVersion = extra[localVersionExtra]!!.toString()
6 | pluginManagement {
7 | repositories {
8 | mavenCentral()
9 | gradlePluginPortal()
10 | exclusiveContent {
11 | forRepository {
12 | mavenLocal()
13 | }
14 | filter {
15 | includeGroupByRegex(".*.jsonschema2dataclass.*")
16 | }
17 | }
18 | }
19 | resolutionStrategy {
20 | eachPlugin {
21 | if (requested.id.name == "jsonschema2dataclass" && requested.version != localVersion) {
22 | useModule("org.jsonschema2dataclass:plugin:$localVersion")
23 | }
24 | }
25 | }
26 | }
27 | rootProject {
28 | buildscript {
29 | configurations.forEach {
30 | it.resolutionStrategy.eachDependency {
31 | if (requested.group == "org.jsonschema2dataclass" && requested.version != localVersion) {
32 | useVersion(localVersion)
33 | }
34 | }
35 | }
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/gradle/libs.dependencies.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | # @see com.android.build.gradle.internal.plugins.BasePlugin.createLintClasspathConfiguration
3 | # @see builder-model//version.properties
4 | # Versions: https://maven.google.com/web/index.html#com.android.tools:common
5 | agp-tools = "31.9.2"
6 |
7 | # JUnit 5 = JUnit Platform ([junit-api]) + JUnit Launcher ([junit-launcher])
8 | # Changelog: https://junit.org/junit5/docs/current/release-notes/index.html
9 | junit5 = "5.12.2"
10 | junit5-platform = "1.12.2"
11 |
12 | [libraries]
13 |
14 | # Compatibility: https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
15 | # Versions: https://maven.google.com/web/index.html#com.android.tools.build:gradle
16 | android-tools = { module = "com.android.tools:common", version.ref = "agp-tools" }
17 |
18 | # Junit for testing
19 | junit-bom = { module = "org.junit:junit-bom", version.ref = "junit5" }
20 | junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
21 | junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit5" }
22 |
23 | # JUnit Engines: https://junit.org/junit5/docs/current/user-guide/index.html#running-tests-build-gradle-engines-configure
24 | junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
25 |
26 | # https://docs.gradle.org/8.4/userguide/upgrading_version_8.html#test_framework_implementation_dependencies
27 | junit-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit5-platform" }
28 |
29 | [bundles]
30 | junit-tests = ["junit-api", "junit-params"]
31 | junit-runtime = ["junit-engine", "junit-launcher"]
32 |
--------------------------------------------------------------------------------
/gradle/plugins.dependencies.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | # https://github.com/gradle-nexus/publish-plugin/releases
3 | nexus = "2.0.0"
4 |
5 | # https://docs.gradle.com/enterprise/gradle-plugin/#release_history
6 | gradle-develocity = "4.0.1"
7 | gradle-publish = "1.3.1"
8 |
9 | # Version of Kotlin Gradle Plugin used for compilation.
10 | kotlin-build = "2.1.20"
11 |
12 | [libraries]
13 | # Plugins as libraries. Used as dependencies for other plugins. it's a bit hacky way, but serves the purpose
14 | #
15 | # WARNING: it's a bit tricky this way to handle moves as gradle doesn't publihs them.
16 |
17 | # Gradle
18 | gradle-develocity = { module = "com.gradle.develocity:com.gradle.develocity.gradle.plugin", version.ref = "gradle-develocity" }
19 | gradle-publish = { module = "com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin", version.ref = "gradle-publish" }
20 |
21 | # Kotlin
22 | kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-build" }
23 | kotlin-gradle-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin-build" }
24 |
25 | [bundles]
26 |
27 | [plugins]
28 | nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }
29 | gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-publish"}
30 | kotlin-build = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-build"}
31 | # Note: internal plugins cannot be used with `alias(libs.plugins....)`, because they don't have version.
32 |
--------------------------------------------------------------------------------
/gradle/processors.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | # Jsonschema2pojo processor
3 | # Versions: https://github.com/joelittlejohn/jsonschema2pojo/releases
4 | processor-jsonschema2pojo = "1.2.2"
5 |
6 | [libraries]
7 | # Plugin Schema processors
8 | jsonschema2pojo = {module = "org.jsonschema2pojo:jsonschema2pojo-core", version.ref="processor-jsonschema2pojo"}
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/b4fcf630f46b1293aa0aa872b9e4a942a833f8c2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/internal/common/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | }
4 |
--------------------------------------------------------------------------------
/internal/common/src/main/kotlin/utils.kt:
--------------------------------------------------------------------------------
1 |
2 | import org.gradle.api.Project
3 | import org.gradle.api.artifacts.VersionCatalogsExtension
4 | import org.gradle.api.plugins.BasePluginExtension
5 | import org.gradle.api.plugins.JavaPluginExtension
6 | import org.gradle.kotlin.dsl.extra
7 | import org.gradle.kotlin.dsl.getByName
8 |
9 | val Project.basePluginExtension: BasePluginExtension
10 | get() = this.extensions.getByName("base")
11 |
12 | val Project.javaPluginExtension: JavaPluginExtension
13 | get() = this.extensions.getByName("java")
14 |
15 | val Project.versionCatalogs: VersionCatalogsExtension
16 | get() = this.extensions.getByName("versionCatalogs")
17 |
18 | fun Project.extraValue(name: String): String? =
19 | if (extra.has(name)) {
20 | extra[name].toString()
21 | } else {
22 | null
23 | }
24 |
25 | fun Project.isExtraEnabled(name: String): Boolean =
26 | project.extraValue(name)?.toBoolean() == true
27 |
28 | val pluginIds = mapOf(
29 | "kotlin-dokka" to "org.jetbrains.dokka",
30 | "nexus-publish" to "io.github.gradle-nexus.publish-plugin",
31 | "gradle-entrprise" to "com.gradle.enterprise",
32 | "gradle-publish" to "com.gradle.plugin-publish",
33 | )
34 |
35 | /** If set, project version will be set to the value. */
36 | const val EXTRA_GIT_VERSION_OVERRIDE = "org.jsonschema2dataclass.internal.git-version-override"
37 |
38 | /** If set, project version will be set to the value. */
39 | const val EXTRA_GIT_VERSION_ENABLE = "org.jsonschema2dataclass.internal.git-version-enable"
40 |
41 | /** If set, gradle plugin will be prepared for a local publication. */
42 | const val EXTRA_LOCAL_PUBLISH = "org.jsonschema2dataclass.internal.local-publish"
43 |
--------------------------------------------------------------------------------
/internal/plugins/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-gradle-plugin`
3 | `kotlin-dsl`
4 | }
5 |
6 | version = "1.0"
7 |
8 | gradlePlugin {
9 | plugins {
10 | create("git-version") {
11 | id = "org.jsonschema2dataclass.internal.git-version"
12 | implementationClass = "org.jsonschema2dataclass.internal.plugin.base.GitVersionPlugin"
13 | description = "Set project version based on git tags and commits."
14 | }
15 | create("kotlin-target") {
16 | id = "org.jsonschema2dataclass.internal.kotlin-target"
17 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.KotlinToolchain"
18 | description = "Set up Kotlin & Java toolchain to use Java 8."
19 | dependencies {
20 | compileOnly(pluginDeps.kotlin.gradle)
21 | }
22 | }
23 | create("settings-develocity") {
24 | id = "org.jsonschema2dataclass.internal.settings-develocity"
25 | implementationClass = "org.jsonschema2dataclass.internal.plugin.base.SettingEnterpriseAccept"
26 | description = "Agree on TOS for Gradle Scans."
27 | dependencies {
28 | compileOnly(pluginDeps.gradle.develocity)
29 | }
30 | }
31 | create("agp-compat") {
32 | id = "org.jsonschema2dataclass.internal.agpcompat"
33 | implementationClass = "org.jsonschema2dataclass.internal.plugin.AGPCompat8Plugin"
34 | description = "Rewrite metadata for AGP modules to be able to build with lower Java versions."
35 | }
36 | create("library-plugin") {
37 | id = "org.jsonschema2dataclass.internal.library"
38 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.LibraryPlugin"
39 | description = "Set up support library defaults."
40 | }
41 | create("gradle-plugin") {
42 | id = "org.jsonschema2dataclass.internal.gradle-plugin"
43 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.GradlePlugin"
44 | description = "Set up gradle plugin defaults."
45 | }
46 | create("processor-version") {
47 | id = "org.jsonschema2dataclass.internal.processor-version"
48 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.ProcessorVersionPlugin"
49 | description = "Set up gradle plugin defaults."
50 | }
51 | create("plugin-publish") {
52 | id = "org.jsonschema2dataclass.internal.plugin-publish"
53 | implementationClass = "org.jsonschema2dataclass.internal.plugin.publishing.PublishingPlugin"
54 | description = "Set up library publishing settings."
55 | }
56 | }
57 | }
58 |
59 | dependencies {
60 | implementation(project(":common"))
61 | }
62 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/EnableFeaturePreviewQuietly.kt:
--------------------------------------------------------------------------------
1 | import org.gradle.api.initialization.Settings
2 |
3 | /** [Feature request](https://github.com/gradle/gradle/issues/19069) */
4 | @Suppress("unused")
5 | fun Settings.enableFeaturePreviewQuietly(name: String, summary: String) {
6 | enableFeaturePreview(name)
7 |
8 | val logger: Any = org.gradle.util.internal.IncubationLogger::class.java
9 | .getDeclaredField("INCUBATING_FEATURE_HANDLER")
10 | .apply { isAccessible = true }
11 | .get(null)
12 |
13 | @Suppress("UNCHECKED_CAST")
14 | val features: MutableSet = org.gradle.internal.featurelifecycle.LoggingIncubatingFeatureHandler::class.java
15 | .getDeclaredField("features")
16 | .apply { isAccessible = true }
17 | .get(logger) as MutableSet
18 |
19 | features.add(summary)
20 | }
21 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/AGPCompat8Plugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.api.artifacts.CacheableRule
6 | import org.gradle.api.artifacts.ComponentMetadataContext
7 | import org.gradle.api.artifacts.ComponentMetadataRule
8 | import org.gradle.api.attributes.java.TargetJvmVersion
9 | import org.gradle.kotlin.dsl.withModule
10 | import javax.inject.Inject
11 |
12 | private val compatComponentsDefault = listOf(
13 | "com.android.tools.build:gradle",
14 | "com.android.tools.build:gradle-api",
15 | "com.android.tools.build:builder",
16 | "com.android.tools.build:builder-model",
17 | "com.android.tools.build:manifest-merger",
18 | )
19 |
20 | // build with this java version
21 | private const val TARGET_JAVA_VERSION = 8
22 |
23 | /**"Fix" metadata of certain libraries to make whole project buildable. */
24 | @Suppress("unused")
25 | class AGPCompat8Plugin : Plugin {
26 | override fun apply(project: Project) {
27 | project.afterEvaluate {
28 | dependencies.components {
29 | // This project still uses Java 8, so let's rewrite the metadata,
30 | // so that the produced jars can still be used with Java 8.
31 | // https://docs.gradle.org/current/userguide/component_metadata_rules.html
32 | for (component in compatComponentsDefault) {
33 | withModule(component) { params(TARGET_JAVA_VERSION) }
34 | }
35 | }
36 | }
37 | }
38 | }
39 |
40 | /**
41 | * taken from https://github.com/TWiStErRob/net.twisterrob.gradle
42 | * licence: MIT licence
43 | */
44 | @CacheableRule
45 | abstract class TargetJvmVersionRule @Inject constructor(
46 | private val jvmVersionOverride: Int,
47 | ) : ComponentMetadataRule {
48 | override fun execute(context: ComponentMetadataContext) {
49 | context.details.allVariants {
50 | attributes {
51 | attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersionOverride)
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/GitVersion.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.base
2 |
3 | import EXTRA_GIT_VERSION_ENABLE
4 | import EXTRA_GIT_VERSION_OVERRIDE
5 | import extraValue
6 | import isExtraEnabled
7 | import org.gradle.api.Project
8 | import java.io.IOException
9 | import java.nio.charset.StandardCharsets
10 | import java.time.LocalDateTime
11 | import java.time.format.DateTimeFormatter
12 | import java.util.Locale
13 | import java.util.concurrent.TimeUnit
14 |
15 | private val regex = Regex("""^v?([0-9.]*(?:-rc\d+)?)-(\d+)-g([0-9a-f]+)(-dirty)?$""")
16 | private const val DEFAULT_VERSION = "-.-.--0-g00000000-dirty"
17 |
18 | /** Obtain git versions or generate one. */
19 | fun gitVersion(project: Project): String {
20 | val versionOverride = project.extraValue(EXTRA_GIT_VERSION_OVERRIDE)
21 | if (versionOverride != null) {
22 | return versionOverride
23 | }
24 |
25 | val commandVersion = when (project.isExtraEnabled(EXTRA_GIT_VERSION_ENABLE)) {
26 | true -> commandVersion(project)
27 | false -> null
28 | }
29 | return processVersionString(commandVersion ?: DEFAULT_VERSION)
30 | }
31 |
32 | /**
33 | * Process version string and return a valid version.
34 | *
35 | * If valid version can't be found, one will be generated.
36 | */
37 | private fun processVersionString(value: String): String {
38 | val match = regex.find(value)
39 | if (match == null) {
40 | val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd.HH-mm-ss", Locale.US))
41 | return "0.0.0-$now"
42 | }
43 |
44 | val (version, commitsAfterTag, revision, dirty) = match.destructured
45 |
46 | return when (commitsAfterTag) {
47 | "0" -> if (dirty.isEmpty()) {
48 | version
49 | } else {
50 | "$version$dirty"
51 | }
52 |
53 | else -> "$version-$commitsAfterTag-$revision$dirty"
54 | }
55 | }
56 |
57 | private const val ONE_MINUTE = 60L
58 |
59 | /**
60 | * Wait for `git` process for at most 1 minute to get a version by tag and state.
61 | *
62 | * Returns null if waited too long or execution wasn't successful
63 | */
64 | private fun commandVersion(project: Project): String? {
65 | try {
66 | val process = ProcessBuilder()
67 | .command("git", "describe", "--tags", "--long", "--dirty")
68 | .redirectOutput(ProcessBuilder.Redirect.PIPE)
69 | .redirectError(ProcessBuilder.Redirect.PIPE)
70 | .start()
71 | process.waitFor(ONE_MINUTE, TimeUnit.SECONDS)
72 | return if (process.exitValue() == 0) {
73 | process
74 | .inputStream
75 | .bufferedReader(StandardCharsets.UTF_8)
76 | .readText()
77 | .trim()
78 | } else {
79 | val output = process
80 | .errorStream
81 | .bufferedReader(StandardCharsets.UTF_8)
82 | .readText()
83 | .trim()
84 | project.logger.error("Process exited with code ${process.exitValue()}: $output")
85 | null
86 | }
87 | } catch (e: UnsupportedOperationException) {
88 | project.logger.error("Can't execute git", e)
89 | } catch (e: IOException) {
90 | project.logger.error("Can't execute git", e)
91 | } catch (e: InterruptedException) {
92 | project.logger.error("process timed out", e)
93 | }
94 | return null
95 | }
96 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/GitVersionPlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.base
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 |
6 | /** Plugin to set project version based on git version. */
7 | @Suppress("unused")
8 | class GitVersionPlugin : Plugin {
9 | override fun apply(project: Project) {
10 | project.version = gitVersion(project)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/SettingEnterpriseAccept.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.base
2 |
3 | import com.gradle.develocity.agent.gradle.DevelocityConfiguration
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.initialization.Settings
6 | import org.gradle.kotlin.dsl.findByType
7 |
8 | /** Configure Gradle Develocity plugin (former Gralde Enterprise) in settings.gradle.kts */
9 | @Suppress("unused")
10 | class SettingEnterpriseAccept : Plugin {
11 | override fun apply(settings: Settings) {
12 | if (settings.plugins.hasPlugin("com.gradle.develocity")) {
13 | settings.extensions.findByType()?.apply {
14 | buildScan {
15 | termsOfUseUrl.set("https://gradle.com/terms-of-service")
16 | termsOfUseAgree.set("yes")
17 | publishing.onlyIf {
18 | it.buildResult.failures.isNotEmpty()
19 | }
20 | }
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/GradlePlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.lib
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.kotlin.dsl.apply
6 | import org.jsonschema2dataclass.internal.plugin.publishing.applySigning
7 | import pluginIds
8 |
9 | /**
10 | * Gradle Plugin basic configuration.
11 | *
12 | * Plugin configures Kotlin toolchain (Java version), and publishing
13 | */
14 | @Suppress("unused")
15 | class GradlePlugin : Plugin {
16 | override fun apply(project: Project) {
17 | project.plugins.apply(KotlinToolchain::class)
18 |
19 | applySigning(project)
20 | project.plugins.apply(pluginIds["gradle-publish"]!!)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/KotlinToolchain.kt:
--------------------------------------------------------------------------------
1 |
2 | package org.jsonschema2dataclass.internal.plugin.lib
3 |
4 | import org.gradle.api.JavaVersion
5 | import org.gradle.api.Plugin
6 | import org.gradle.api.Project
7 | import org.gradle.api.plugins.JavaPluginExtension
8 | import org.gradle.jvm.toolchain.JavaLanguageVersion
9 | import org.gradle.kotlin.dsl.configure
10 |
11 | /** Target java version to build plugin code with. */
12 | private const val TARGET_JAVA_VERSION = 8
13 |
14 | /** Configure Java 8 toolchain for build Java versions >= 11. */
15 | @Suppress("unused")
16 | class KotlinToolchain : Plugin {
17 | override fun apply(project: Project) {
18 | // Configure Java 8 toolchain for the latest JVM
19 | if (JavaVersion.current() >= JavaVersion.VERSION_11) {
20 | project.extensions.configure {
21 | withSourcesJar()
22 | toolchain.languageVersion.set(JavaLanguageVersion.of(TARGET_JAVA_VERSION))
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/LibraryPlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.lib
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.kotlin.dsl.apply
6 | import org.jsonschema2dataclass.internal.plugin.publishing.PublishingPlugin
7 |
8 | /**
9 | * Support library basic configuration.
10 | *
11 | * Plugin configures Kotlin toolchain (Java version) and publishing to Maven Central
12 | */
13 | @Suppress("unused")
14 | class LibraryPlugin : Plugin {
15 | override fun apply(project: Project) {
16 | project.plugins.apply(KotlinToolchain::class)
17 | project.plugins.apply(PublishingPlugin::class)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/ProcessorVersionPlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.lib
2 |
3 | import org.gradle.api.DefaultTask
4 | import org.gradle.api.GradleException
5 | import org.gradle.api.Plugin
6 | import org.gradle.api.Project
7 | import org.gradle.api.artifacts.MinimalExternalModuleDependency
8 | import org.gradle.api.file.DirectoryProperty
9 | import org.gradle.api.plugins.JavaPluginExtension
10 | import org.gradle.api.provider.Property
11 | import org.gradle.api.tasks.Input
12 | import org.gradle.api.tasks.Optional
13 | import org.gradle.api.tasks.OutputDirectory
14 | import org.gradle.api.tasks.OutputFile
15 | import org.gradle.api.tasks.SourceSet
16 | import org.gradle.api.tasks.SourceSetContainer
17 | import org.gradle.api.tasks.TaskAction
18 | import org.gradle.kotlin.dsl.apply
19 | import org.gradle.util.GradleVersion
20 | import versionCatalogs
21 | import java.io.File
22 | import java.util.Properties
23 |
24 | private const val PROCESSOR_VERSION_EXTENSION = "processorVersion"
25 | private const val PROCESSOR_VERSION_CATALOG = "processors"
26 | private const val DEFAULT_TARGET_FOLDER_BASE = "generated/sources/processorVersion"
27 | private const val DEFAULT_TARGET_FILENAME = "processor.properties"
28 |
29 | private val javaPlugins = listOf("java", "java-library")
30 |
31 | /**
32 | * Plugin to include processor path to metadata properties file.
33 | *
34 | * Used to put processor.properties into the output classpath of the library.
35 | *
36 | * This file is intended to be read by processor task impl to inject a runtime dependency to run processor.
37 | */
38 | @Suppress("unused")
39 | class ProcessorVersionPlugin : Plugin {
40 | override fun apply(project: Project) {
41 | for (pluginId in javaPlugins) {
42 | project.plugins.withId(pluginId) {
43 | project.apply()
44 | }
45 | }
46 | }
47 | }
48 |
49 | class ProcessorVersionPluginImpl : Plugin {
50 | private fun mainSourceSet(project: Project): SourceSet =
51 | if (GradleVersion.current() < GradleVersion.version("7.1")) {
52 | obtainJavaSourceSetContainerV6(project)
53 | } else {
54 | obtainJavaSourceSetContainerV7(project)
55 | }
56 |
57 | override fun apply(project: Project) {
58 | val extension = project.extensions.create(PROCESSOR_VERSION_EXTENSION, ProcessorVersionPExtension::class.java)
59 | extension.fieldName.convention("processor")
60 | extension.outputFolder.convention(project.layout.buildDirectory.dir(DEFAULT_TARGET_FOLDER_BASE))
61 | extension.filename.convention(DEFAULT_TARGET_FILENAME)
62 |
63 | val task = project.tasks.register("processorVersion", ProcessorVersionGeneratorTask::class.java) {
64 | this.library.set(extension.library)
65 | this.fieldName.set(extension.fieldName)
66 | this.filename.set(extension.filename)
67 | this.outputFolder.set(extension.outputFolder)
68 | }
69 |
70 | project.tasks.named("processResources").configure {
71 | dependsOn(task)
72 | }
73 | project.tasks.named("compileKotlin").configure {
74 | dependsOn(task)
75 | }
76 |
77 | task.configure {
78 | val javaSourceSet = mainSourceSet(project).resources
79 | javaSourceSet.srcDirs(task)
80 | }
81 | }
82 | }
83 |
84 | abstract class ProcessorVersionPExtension {
85 | @get:Input
86 | abstract val library: Property
87 |
88 | @get:Input
89 | @get:Optional
90 | abstract val fieldName: Property
91 |
92 | @get:Input
93 | @get:Optional
94 | abstract val filename: Property
95 |
96 | @get:OutputFile
97 | @get:Optional
98 | abstract val outputFolder: DirectoryProperty
99 | }
100 |
101 | abstract class ProcessorVersionGeneratorTask : DefaultTask() {
102 | @get:Input
103 | abstract val library: Property
104 |
105 | @get:Input
106 | abstract val fieldName: Property
107 |
108 | @get:Input
109 | @get:Optional
110 | abstract val filename: Property
111 |
112 | @get:OutputDirectory
113 | abstract val outputFolder: DirectoryProperty
114 |
115 | @TaskAction
116 | fun action() {
117 | if (filename.get().contains("..")) {
118 | throw GradleException("filename path must not contain `..`")
119 | }
120 |
121 | val dependency: MinimalExternalModuleDependency = project
122 | .versionCatalogs
123 | .named(PROCESSOR_VERSION_CATALOG)
124 | .findLibrary(library.get())
125 | .orElseThrow {
126 | GradleException(
127 | "Unable resolve library for ${library.get()} in catalog $PROCESSOR_VERSION_CATALOG",
128 | )
129 | }
130 | .get()
131 |
132 | val requiredVersion = dependency.versionConstraint.requiredVersion
133 | val group = dependency.module.group
134 | val name = dependency.module.name
135 |
136 | val identifier = "$group:$name:$requiredVersion"
137 |
138 | val outputFile = this.outputFolder.get().asFile.resolve(filename.get())
139 |
140 | if (project.logger.isDebugEnabled) {
141 | project.logger.debug("Found library with identifier `$identifier`, writing to ${outputFile.absolutePath}")
142 | }
143 | outputFile.ensureParentDirsCreated()
144 |
145 | outputFile.writer().apply {
146 | val p = Properties()
147 | p[fieldName.get()] = identifier
148 | p.store(this, null)
149 | }
150 | }
151 | }
152 |
153 | /**
154 | * Obtain java source sets in Gradle 6.0 - 7.0.2
155 | */
156 | @Suppress("DEPRECATION")
157 | private fun obtainJavaSourceSetContainerV6(project: Project): SourceSet =
158 | obtainSourceSetContainer(project.convention.plugins["java"]!!)
159 | .named("main")
160 | .get()
161 |
162 | private fun obtainSourceSetContainer(value: Any): SourceSetContainer {
163 | val method = value::class.java.getDeclaredMethod("getSourceSets")
164 | return method.invoke(value) as SourceSetContainer
165 | }
166 |
167 | /**
168 | * Obtain java source sets in Gradle 7.3+.
169 | */
170 | private fun obtainJavaSourceSetContainerV7(project: Project): SourceSet =
171 | project
172 | .extensions
173 | .getByType(JavaPluginExtension::class.java)
174 | .sourceSets
175 | .named("main")
176 | .get()
177 |
178 | private fun File.ensureParentDirsCreated() {
179 | val parentFile = parentFile
180 | if (!parentFile.exists()) {
181 | check(parentFile.mkdirs()) {
182 | "Cannot create parent directories for $this"
183 | }
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/PublishingPlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.publishing
2 |
3 | import javaPluginExtension
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.Project
6 | import org.gradle.kotlin.dsl.configure
7 | import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
8 |
9 | /**
10 | * Heavily inspired by
11 | * [net.twisterrob.gradle](https://github.com/TWiStErRob/net.twisterrob.gradle])
12 | * publishing code
13 | *
14 | * Disable automated publishing [completed feature
15 | * request](https://github.com/gradle/gradle/issues/11611) -
16 | * not working with gradle-publish plugin version 1.0 and above
17 | *
18 | */
19 | class PublishingPlugin : Plugin {
20 | override fun apply(project: Project) {
21 | val signing = applySigning(project)
22 |
23 | val javaPluginExtension = project.javaPluginExtension
24 | javaPluginExtension.withSourcesJar()
25 |
26 | applyPublishing(project, signing)
27 |
28 | project.plugins.withId("java-gradle-plugin") {
29 | project.configure {
30 | isAutomatedPublishing = false
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/publishing.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.publishing
2 |
3 | import basePluginExtension
4 | import groovy.util.Node
5 | import groovy.util.NodeList
6 | import org.gradle.api.Project
7 | import org.gradle.api.publish.PublishingExtension
8 | import org.gradle.api.publish.maven.MavenPublication
9 | import org.gradle.kotlin.dsl.configure
10 | import org.gradle.kotlin.dsl.get
11 | import org.gradle.kotlin.dsl.getByName
12 | import org.gradle.kotlin.dsl.register
13 | import org.gradle.plugins.signing.SigningExtension
14 |
15 | fun applyPublishing(project: Project, signing: Boolean = false) {
16 | project.plugins.apply("maven-publish")
17 |
18 | project.configure {
19 | publications {
20 | register("release") release@{
21 | if (signing) {
22 | project.configure {
23 | sign(this@release)
24 | }
25 | }
26 | setupModuleIdentity(project)
27 | from(project.components["java"])
28 | setupLinks()
29 | }
30 | }
31 | }
32 | project.afterEvaluate {
33 | project.configure {
34 | publications {
35 | getByName("release") {
36 | reorderNodes(project)
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
43 | private fun MavenPublication.setupModuleIdentity(project: Project) {
44 | project.afterEvaluate {
45 | artifactId = project.basePluginExtension.archivesName.get()
46 | version = project.version as String
47 |
48 | pom {
49 | val projectDescription = project.description?.takeIf { it.contains(": ") }
50 | ?: error("$project must have a description with format: \"Module Display Name: Module description.\"")
51 | name.set(projectDescription.substringBefore(": ").also { check(it.isNotBlank()) })
52 | description.set(projectDescription.substringAfter(": ").also { check(it.isNotBlank()) })
53 | }
54 | }
55 | }
56 |
57 | private fun MavenPublication.setupLinks() {
58 | pom {
59 | url.set("https://github.com/jsonschema2dataclass/js2d-gradle")
60 | scm {
61 | connection.set("scm:git:github.com/jsonschema2dataclass/js2d-gradle.git")
62 | developerConnection.set("scm:git:github.com/jsonschema2dataclass/js2d-gradle.git")
63 | url.set("https://github.com/jsonschema2dataclass/js2d-gradle/tree/master")
64 | }
65 | licenses {
66 | license {
67 | name.set("The Apache License, Version 2.0")
68 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
69 | }
70 | }
71 | developers {
72 | developer {
73 | id.set("eirnym")
74 | name.set("Eir Nym")
75 | email.set("eirnym@gmail.com")
76 | }
77 | }
78 | }
79 | }
80 |
81 | private fun MavenPublication.reorderNodes(project: Project) {
82 | fun Node.getChildren(localName: String): NodeList =
83 | this.get(localName) as NodeList
84 |
85 | fun NodeList.nodes(): List =
86 | (this as Iterable<*>).filterIsInstance()
87 |
88 | fun Node.getChild(localName: String): Node? =
89 | this.getChildren(localName).nodes().singleOrNull()
90 |
91 | project.afterEvaluate {
92 | pom.withXml {
93 | asNode().apply {
94 | val lastNodes = sequenceOf(
95 | getChild("modelVersion"),
96 | getChild("groupId"),
97 | getChild("artifactId"),
98 | getChild("version"),
99 | getChild("name"),
100 | getChild("description"),
101 | getChild("url"),
102 | getChild("dependencies"),
103 | getChild("scm"),
104 | getChild("developers"),
105 | getChild("licenses"),
106 | )
107 | .filterNotNull()
108 | .toList()
109 |
110 | // lastNodes.forEach { println("found node ${it.name()}") }
111 | lastNodes.forEach { remove(it) }
112 | lastNodes.forEach { append(it) }
113 | }
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/signing.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.plugin.publishing
2 |
3 | import org.gradle.api.Project
4 | import org.gradle.kotlin.dsl.configure
5 | import org.gradle.kotlin.dsl.provideDelegate
6 | import org.gradle.plugins.signing.SigningExtension
7 |
8 | /**
9 | * -PsigningKey to gradlew, or ORG_GRADLE_PROJECT_signingKey env var
10 | *
11 | * -PsigningPassword to gradlew, or ORG_GRADLE_PROJECT_signingPassword env var
12 | */
13 | fun applySigning(project: Project): Boolean {
14 | // val signingKeyId: String? by project // Gradle 6+ only
15 | val signingKey: String? by project
16 | val signingPassword: String? by project
17 |
18 | val credentials = if (signingKey != null && signingPassword != null) {
19 | signingKey to signingPassword
20 | } else {
21 | return false
22 | }
23 |
24 | project.plugins.apply("signing")
25 | project.configure {
26 | useInMemoryPgpKeys(credentials.first, credentials.second)
27 | }
28 | return true
29 | }
30 |
--------------------------------------------------------------------------------
/internal/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "Internal plugins"
2 |
3 | include(":common")
4 | include(":plugins")
5 |
6 | @Suppress("UnstableApiUsage")
7 | dependencyResolutionManagement {
8 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
9 | repositories {
10 | gradlePluginPortal()
11 | mavenCentral()
12 | }
13 | versionCatalogs {
14 | create("libs") {
15 | from(files("../gradle/libs.dependencies.toml"))
16 | }
17 | create("pluginDeps") {
18 | from(files("../gradle/plugins.dependencies.toml"))
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/plugin-gradle/common/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | }
5 |
6 | base.archivesName.set("jsonschema2dataclass-plugin-common")
7 | description = "Common processor compatibility layer: Compatibility layer for schema processors."
8 |
--------------------------------------------------------------------------------
/plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/ext/package-info.java:
--------------------------------------------------------------------------------
1 | /** All Gradle Extensions are defined here. */
2 | package org.jsonschema2dataclass.ext;
3 |
--------------------------------------------------------------------------------
/plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/Js2dProcessor.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal
2 |
3 | import org.gradle.api.Project
4 | import org.gradle.api.artifacts.Configuration
5 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase
6 |
7 | /** Processor definition. */
8 | interface Js2dProcessor {
9 | /** Intended task name and description. */
10 | fun toolNameForTask(): Pair
11 |
12 | /** Class of a task for a generator. */
13 | fun generatorTaskClass(): Class>
14 |
15 | /** Add bare minimum tooling dependencies into configuration. */
16 | fun toolingMinimalDependencies(project: Project, configuration: Configuration)
17 | }
18 |
--------------------------------------------------------------------------------
/plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/RegisterTasks.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal
2 |
3 | import org.gradle.api.Action
4 | import org.gradle.api.Project
5 | import org.gradle.api.Task
6 | import org.gradle.api.tasks.TaskProvider
7 | import org.jsonschema2dataclass.internal.task.DEFAULT_SCHEMA_PATH
8 | import java.nio.file.Path
9 |
10 | typealias ProcessorRegistrationCallback = (
11 | suffixes: Map,
12 | registerDependencies: (taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action) -> Unit,
13 | ) -> Unit
14 |
15 | interface GradlePluginRegistration {
16 | fun defaultSchemaPath(project: Project): Path {
17 | return defaultSchemaPathInternal(project) ?: project.file(DEFAULT_SCHEMA_PATH).toPath()
18 | }
19 |
20 | fun defaultSchemaPathInternal(project: Project): Path?
21 |
22 | fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback)
23 | }
24 |
--------------------------------------------------------------------------------
/plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/task/Consts.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.task
2 |
3 | /** Plugin ID to refer in messages */
4 | const val PLUGIN_ID = "org.jsonschema2dataclass"
5 |
6 | /** Configuration name for tools */
7 | const val JS2D_CONFIGURATION_NAME = "jsonschema2dataclass"
8 |
9 | /** Configuration to put plugin dependencies to */
10 | const val JS2D_PLUGINS_CONFIGURATION_NAME = "jsonschema2dataclassPlugins"
11 |
12 | /** Default schema locations under project name. Should be changed */
13 | const val DEFAULT_SCHEMA_PATH = "src/main/json"
14 |
15 | /** Default folder to store generated files under build folder */
16 | const val DEFAULT_TARGET_FOLDER_BASE = "generated/sources/js2d"
17 |
18 | /** Extension name for jsonschema2pojo processor */
19 | const val JS2P_EXTENSION_NAME = "jsonSchema2Pojo"
20 |
21 | /** Base task name for jsonschema2pojo processor */
22 | const val JS2D_TASK_NAME = "generateJsonSchema2DataClass"
23 |
24 | /** Processor name to generate task names */
25 | const val JS2P_TOOL_NAME = "Js2p"
26 |
--------------------------------------------------------------------------------
/plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/task/Js2dGeneratorTaskBase.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.task
2 |
3 | import org.gradle.api.DefaultTask
4 | import org.gradle.api.file.DirectoryProperty
5 | import org.gradle.api.file.FileCollection
6 | import org.gradle.api.provider.Provider
7 | import org.gradle.api.tasks.Classpath
8 | import org.gradle.api.tasks.Internal
9 | import org.gradle.api.tasks.Nested
10 | import org.gradle.api.tasks.OutputDirectory
11 | import org.gradle.api.tasks.TaskAction
12 | import org.gradle.workers.WorkQueue
13 | import org.gradle.workers.WorkerExecutor
14 | import java.util.UUID
15 | import javax.inject.Inject
16 |
17 | abstract class Js2dGeneratorTaskBase @Inject constructor(
18 | private val workerExecutor: WorkerExecutor,
19 | ) : DefaultTask() {
20 | @get:Nested
21 | abstract var configuration: ConfigType // Should not be
22 |
23 | @get:OutputDirectory
24 | abstract val targetDirectory: DirectoryProperty
25 |
26 | @get:Internal
27 | abstract var uuid: UUID
28 |
29 | @get:Classpath
30 | val js2dConfiguration: Provider =
31 | project.configurations.named(JS2D_CONFIGURATION_NAME)
32 |
33 | @get:Classpath
34 | val js2dConfigurationPlugins: Provider = project.configurations.named(
35 | JS2D_PLUGINS_CONFIGURATION_NAME,
36 | )
37 |
38 | abstract fun submit(workQueue: WorkQueue)
39 |
40 | @TaskAction
41 | fun action() {
42 | val workerClassPath = js2dConfiguration.get() + js2dConfigurationPlugins
43 | val workQueue = workerExecutor.processIsolation {
44 | // Set encoding (work-around for https://github.com/gradle/gradle/issues/13843)
45 | // TODO: fixed in Gradle 8.3
46 | forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8")
47 |
48 | classpath.from(workerClassPath)
49 | }
50 | submit(workQueue)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/agp34/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | }
5 |
6 | base.archivesName.set("jsonschema2dataclass-agp34-api-compat")
7 | description = "AGP 3 and 4 Compatibility layer: Compatibility layer for Android Gradle Plugin 3.x and 4.x."
8 |
9 | dependencies {
10 | compileOnly(projects.pluginGradle.common)
11 | compileOnly(agp.android.gradle.v4x) {
12 | exclude(group = "org.jetbrains.kotlin")
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/agp34/src/main/kotlin/org/jsonschema2dataclass/internal/compat/android/AGP34PluginRegistration.kt:
--------------------------------------------------------------------------------
1 | // TODO: drop this module as AGP 3.x doesn't really used anymore
2 | package org.jsonschema2dataclass.internal.compat.android
3 |
4 | import com.android.build.gradle.AppExtension
5 | import com.android.build.gradle.BaseExtension
6 | import com.android.build.gradle.LibraryExtension
7 | import com.android.build.gradle.api.ApplicationVariant
8 | import com.android.build.gradle.api.BaseVariant
9 | import com.android.build.gradle.api.LibraryVariant
10 | import org.gradle.api.Action
11 | import org.gradle.api.DomainObjectCollection
12 | import org.gradle.api.DomainObjectSet
13 | import org.gradle.api.Project
14 | import org.gradle.api.Task
15 | import org.gradle.api.tasks.SourceSet
16 | import org.gradle.api.tasks.TaskProvider
17 | import org.gradle.configurationcache.extensions.capitalized
18 | import org.gradle.kotlin.dsl.invoke
19 | import org.jsonschema2dataclass.internal.GradlePluginRegistration
20 | import org.jsonschema2dataclass.internal.ProcessorRegistrationCallback
21 | import java.nio.file.Path
22 |
23 | /** Register a processor task for Android Gradle Plugin 3.x & 4.x using AGP 3 API. */
24 | class AGP34PluginRegistration : GradlePluginRegistration {
25 | override fun defaultSchemaPathInternal(project: Project): Path? =
26 | project.extensions
27 | .getByType(BaseExtension::class.java)
28 | .sourceSets.find { it.name.startsWith(SourceSet.MAIN_SOURCE_SET_NAME) }
29 | ?.resources
30 | ?.srcDirs
31 | ?.first()
32 | ?.toPath()
33 |
34 | override fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback) {
35 | obtainAndroidLibraryVariants(project)?.all {
36 | createTasksForVariant(this, callback)
37 | }
38 |
39 | obtainAndroidApplicationVariants(project)?.all {
40 | createTasksForVariant(this, callback)
41 | }
42 | }
43 | }
44 |
45 | private fun createTasksForVariant(variant: T, callback: ProcessorRegistrationCallback) {
46 | callback.invoke(
47 | mapOf("variant" to variant.name),
48 | ) { taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action ->
49 | variant.registerJavaGeneratingTask(taskProvider.get(), listOfNotNull(targetPath?.toFile()))
50 | dependsOn("compile${variant.name.capitalized()}Kotlin")
51 | }
52 | }
53 |
54 | private fun obtainAndroidLibraryVariants(project: Project): DomainObjectCollection? =
55 | project.extensions
56 | .findByType(LibraryExtension::class.java)
57 | ?.libraryVariants
58 |
59 | private fun obtainAndroidApplicationVariants(project: Project): DomainObjectSet? =
60 | project.extensions
61 | .findByType(AppExtension::class.java)
62 | ?.applicationVariants
63 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/agp7/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | id("org.jsonschema2dataclass.internal.agpcompat")
5 | }
6 |
7 | base.archivesName.set("jsonschema2dataclass-agp7-api-compat")
8 | description = "AGP 7 Compatibility layer: Compatibility layer for Android Gradle Plugin 7.x."
9 |
10 | dependencies {
11 | compileOnly(projects.pluginGradle.common)
12 | compileOnly(agp.android.gradle.v7x) {
13 | exclude(group = "org.jetbrains.kotlin")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/agp7/src/main/kotlin/org/jsonschema2dataclass/internal/compat/android/AGP347PluginRegistration.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("DEPRECATION")
2 |
3 | package org.jsonschema2dataclass.internal.compat.android
4 |
5 | import com.android.build.api.variant.AndroidComponentsExtension
6 | import com.android.build.gradle.AppExtension
7 | import com.android.build.gradle.BaseExtension
8 | import com.android.build.gradle.LibraryExtension
9 | import com.android.build.gradle.api.ApplicationVariant
10 | import com.android.build.gradle.api.BaseVariant
11 | import com.android.build.gradle.api.LibraryVariant
12 | import com.android.build.gradle.internal.tasks.factory.dependsOn
13 | import org.gradle.api.Action
14 | import org.gradle.api.DomainObjectCollection
15 | import org.gradle.api.DomainObjectSet
16 | import org.gradle.api.Project
17 | import org.gradle.api.Task
18 | import org.gradle.api.tasks.SourceSet
19 | import org.gradle.api.tasks.TaskProvider
20 | import org.gradle.configurationcache.extensions.capitalized
21 | import org.gradle.kotlin.dsl.getByName
22 | import org.gradle.kotlin.dsl.invoke
23 | import org.jsonschema2dataclass.internal.GradlePluginRegistration
24 | import org.jsonschema2dataclass.internal.ProcessorRegistrationCallback
25 | import java.nio.file.Path
26 |
27 | /** Register a processor task for Android Gradle Plugin 7.x using AGP 3 API. */
28 | @Suppress("unused")
29 | class AGP347PluginRegistration : GradlePluginRegistration {
30 | override fun defaultSchemaPathInternal(project: Project): Path? =
31 | project.extensions
32 | .getByType(BaseExtension::class.java)
33 | .sourceSets.find { it.name.startsWith(SourceSet.MAIN_SOURCE_SET_NAME) }
34 | ?.resources
35 | ?.srcDirs
36 | ?.first()
37 | ?.toPath()
38 |
39 | override fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback) {
40 | val androidComponents: AndroidComponentsExtension<*, *, *> =
41 | project.extensions.getByName>("androidComponents")
42 | androidComponents.onVariants { variant ->
43 | variant.buildConfigFields
44 | }
45 | obtainAndroidLibraryVariants(project)?.all {
46 | createTasksForVariant(this, callback)
47 | }
48 |
49 | obtainAndroidApplicationVariants(project)?.all {
50 | createTasksForVariant(this, callback)
51 | }
52 | }
53 | }
54 |
55 | private fun createTasksForVariant(
56 | variant: T,
57 | callback: ProcessorRegistrationCallback,
58 | ) {
59 | callback.invoke(
60 | mapOf("variant" to variant.name),
61 | ) { taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action ->
62 | taskProvider.dependsOn(variant.processJavaResourcesProvider)
63 | variant.javaCompileProvider.dependsOn(taskProvider)
64 | if (targetPath != null) {
65 | variant.registerJavaGeneratingTask(taskProvider, listOfNotNull(targetPath.toFile()))
66 | variant.addJavaSourceFoldersToModel(listOfNotNull(targetPath.toFile()))
67 | } else {
68 | variant.registerJavaGeneratingTask(taskProvider)
69 | }
70 | dependsOn("compile${variant.name.capitalized()}Kotlin")
71 | }
72 | }
73 |
74 | private fun obtainAndroidLibraryVariants(project: Project): DomainObjectCollection? =
75 | project.extensions
76 | .findByType(LibraryExtension::class.java)
77 | ?.libraryVariants
78 |
79 | private fun obtainAndroidApplicationVariants(project: Project): DomainObjectSet? =
80 | project.extensions
81 | .findByType(AppExtension::class.java)
82 | ?.applicationVariants
83 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/android/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | }
5 |
6 | base.archivesName.set("jsonschema2dataclass-agp-api-compat")
7 | description = "Common AGP Compatibility layer: " +
8 | "Common compatibility layer for supported versions of Android Gradle Plugin."
9 |
10 | dependencies {
11 | // for Android build tools version :)
12 | compileOnly(libs.android.tools) {
13 | exclude(group = "org.jetbrains.kotlin")
14 | }
15 |
16 | implementation(projects.pluginGradle.compat.kotlin)
17 | implementation(projects.pluginGradle.common)
18 | implementation(projects.pluginGradle.compat.agp34)
19 | implementation(projects.pluginGradle.compat.agp7)
20 | }
21 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/android/src/main/kotlin/org/jsonschema2dataclass/internal/compat/android/Register.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.compat.android
2 |
3 | import org.gradle.api.GradleScriptException
4 | import org.gradle.api.ProjectConfigurationException
5 | import org.jsonschema2dataclass.internal.GradlePluginRegistration
6 | import org.jsonschema2dataclass.internal.task.PLUGIN_ID
7 |
8 | fun androidProcessorRegistrationSelector(): GradlePluginRegistration =
9 | findClass(androidProcessorRegistrationClassName()).getDeclaredConstructor().newInstance()
10 |
11 | private const val AGP_3 = 3
12 | private const val AGP_4 = 4
13 | private const val AGP_7 = 7
14 |
15 | /** Return class to bind Android Gradle Plugin projects. */
16 | private fun androidProcessorRegistrationClassName(): String =
17 | when (com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.split(".")[0].toInt()) {
18 | AGP_3, AGP_4 -> "org.jsonschema2dataclass.internal.compat.android.AGP34PluginRegistration"
19 | AGP_7 -> "org.jsonschema2dataclass.internal.compat.android.AGP347PluginRegistration"
20 | else -> throw ProjectConfigurationException("$PLUGIN_ID: Plugin supports AGP 3.x, 4.x or 7.x", listOf())
21 | }
22 |
23 | /** Load proper class to bind Android Gradle Plugin projects. */
24 | private inline fun findClass(className: String): Class {
25 | return try {
26 | @Suppress("UNCHECKED_CAST")
27 | Class.forName(className, true, C::class.java.classLoader) as Class
28 | } catch (e: ClassNotFoundException) {
29 | throw GradleScriptException("Unable to find class $className", e)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/java/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | }
5 |
6 | base.archivesName.set("jsonschema2dataclass-java-plugin-compat")
7 | description = "Java Plugin Compatibility layer: Compatibility layer for Java Plugin."
8 |
9 | dependencies {
10 | implementation(projects.pluginGradle.common)
11 | }
12 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/java/src/main/kotlin/org/jsonschema2dataclass/internal/compat/java/JavaPluginRegistration.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.compat.java
2 |
3 | import org.gradle.api.Action
4 | import org.gradle.api.Project
5 | import org.gradle.api.Task
6 | import org.gradle.api.plugins.JavaPluginExtension
7 | import org.gradle.api.tasks.SourceSet
8 | import org.gradle.api.tasks.SourceSetContainer
9 | import org.gradle.api.tasks.TaskProvider
10 | import org.gradle.util.GradleVersion
11 | import org.jsonschema2dataclass.internal.GradlePluginRegistration
12 | import org.jsonschema2dataclass.internal.ProcessorRegistrationCallback
13 | import java.nio.file.Path
14 |
15 | /**
16 | * Registers a processor task using Java & Kotlin plugins.
17 | *
18 | * Additionally, this handles Lombok compatibility
19 | */
20 | class JavaPluginRegistration : GradlePluginRegistration {
21 | private fun mainSourceSet(project: Project): SourceSet =
22 | if (GradleVersion.current() < GradleVersion.version("7.1")) {
23 | obtainJavaSourceSetContainerV6(project)
24 | } else {
25 | obtainJavaSourceSetContainerV7(project)
26 | }
27 |
28 | override fun defaultSchemaPathInternal(project: Project): Path? =
29 | mainSourceSet(project)
30 | .output
31 | .resourcesDir
32 | ?.toPath()
33 | ?.resolve("json")
34 |
35 | override fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback) {
36 | val javaSourceSet = mainSourceSet(project).java
37 |
38 | callback.invoke(
39 | mapOf(),
40 | ) { taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action ->
41 | taskProvider.configure {
42 | dependsOn(project.tasks.named("processResources"))
43 | }
44 |
45 | dependsOn.execute("generateEffectiveLombokConfig")
46 |
47 | if (targetPath != null) {
48 | javaSourceSet.srcDirs(taskProvider)
49 | }
50 | }
51 | }
52 | }
53 |
54 | // TODO: split this out to have better compatibility
55 |
56 | /** Obtain java source sets in Gradle 6.0 - 7.0.2 */
57 | @Suppress("DEPRECATION")
58 | private fun obtainJavaSourceSetContainerV6(project: Project): SourceSet =
59 | obtainSourceSetContainer(project.convention.plugins["java"]!!)
60 | .named("main")
61 | .get()
62 |
63 | /** Call `getSourceSets` method existed in Gradle 6.0 - 7.0.2. */
64 | private fun obtainSourceSetContainer(value: Any): SourceSetContainer {
65 | val method = value::class.java.getDeclaredMethod("getSourceSets")
66 | return method.invoke(value) as SourceSetContainer
67 | }
68 |
69 | /** Obtain java source sets in Gradle 7.3 and above */
70 | private fun obtainJavaSourceSetContainerV7(project: Project): SourceSet =
71 | project
72 | .extensions
73 | .getByType(JavaPluginExtension::class.java)
74 | .sourceSets
75 | .named("main")
76 | .get()
77 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/kotlin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | }
5 |
6 | base.archivesName.set("jsonschema2dataclass-kotlin-compat")
7 | description = "Plugin Kotlin Compat: Kotlin compatibility functions"
8 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/kotlin/src/main/kotlin/org/jsonschema2dataclass/internal/compat/kotlin/KotlinCompat.kt:
--------------------------------------------------------------------------------
1 | /** Kotlin compatibility shims to smooth version differences */
2 | package org.jsonschema2dataclass.internal.compat.kotlin
3 |
4 | /** Kotlin version independent functions as we support quite wide range of Gradle. */
5 |
6 | import java.util.Locale
7 |
8 | /**
9 | * Kotlin-independent version of making string uppercase
10 | */
11 | @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "KotlinConstantConditions")
12 | fun String.asUppercase(): String = (this as java.lang.String).toUpperCase(Locale.ROOT)
13 |
14 | /** Kotlin-independent version of capitalization. */
15 | fun CharSequence.capitalized(): String = this[0].toString().asUppercase() + substring(1)
16 |
--------------------------------------------------------------------------------
/plugin-gradle/compat/kotlin/src/main/kotlin/org/jsonschema2dataclass/internal/compat/kotlin/TestsNeeded.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.compat.kotlin
2 |
3 | @Target(
4 | AnnotationTarget.CLASS,
5 | AnnotationTarget.FUNCTION,
6 | AnnotationTarget.TYPE_PARAMETER,
7 | AnnotationTarget.VALUE_PARAMETER,
8 | AnnotationTarget.EXPRESSION,
9 | )
10 | @Retention(AnnotationRetention.SOURCE)
11 | annotation class TestsNeeded
12 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `java-gradle-plugin` // Gradle plugin base
3 | `kotlin-dsl`
4 | id("org.jsonschema2dataclass.internal.gradle-plugin")
5 | }
6 |
7 | @Suppress("UnstableApiUsage")
8 | gradlePlugin {
9 | website.set("https://github.com/jsonschema2dataclass/js2d-gradle")
10 | vcsUrl.set("https://github.com/jsonschema2dataclass/js2d-gradle.git")
11 |
12 | plugins {
13 | create("jsonschema2dataclassPlugin") {
14 | id = "org.jsonschema2dataclass"
15 |
16 | implementationClass = "org.jsonschema2dataclass.Js2dPlugin"
17 | displayName = "jsonschema2dataclass plugin"
18 | description =
19 | "A plugins that generates Java sources from Json Schema. " +
20 | "Please, see the GitHub page for details"
21 |
22 | tags.set(
23 | listOf(
24 | "json-schema",
25 | "jsonschema",
26 | "generator",
27 | "pojo",
28 | "jsonschema2pojo",
29 | "dataclass",
30 | "data",
31 | "json",
32 | "generation",
33 | "jsonschema2dataclass",
34 | "java",
35 | "kotlin",
36 | "groovy",
37 | "android",
38 | ),
39 | )
40 | }
41 | }
42 | }
43 |
44 | dependencies {
45 | implementation(projects.pluginGradle.common) {
46 | exclude(group = "org.jetbrains.kotlin")
47 | }
48 |
49 | // Java language compatibility layer
50 | implementation(projects.pluginGradle.compat.kotlin)
51 |
52 | // Processors
53 | implementation(projects.pluginGradle.processors.jsonschema2pojo)
54 |
55 | // Gradle plugin compatibility
56 | implementation(projects.pluginGradle.compat.java)
57 | implementation(projects.pluginGradle.compat.android)
58 |
59 | testImplementation(libs.bundles.junit.tests)
60 | testRuntimeOnly(libs.bundles.junit.runtime)
61 | testImplementation(gradleTestKit())
62 | }
63 |
64 | tasks.test {
65 | javaLauncher = javaToolchains.launcherFor {
66 | languageVersion = JavaLanguageVersion.of(JavaVersion.current().majorVersion)
67 | }
68 | useJUnitPlatform()
69 | systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_method")
70 | systemProperty("junit.jupiter.execution.parallel.enabled", "true")
71 | }
72 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/main/kotlin/org/jsonschema2dataclass/Js2dPlugin.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.api.artifacts.Configuration
6 | import org.gradle.kotlin.dsl.apply
7 | import org.jsonschema2dataclass.ext.Js2pExtension
8 | import org.jsonschema2dataclass.internal.GradlePluginRegistration
9 | import org.jsonschema2dataclass.internal.Js2dProcessor
10 | import org.jsonschema2dataclass.internal.compat.android.androidProcessorRegistrationSelector
11 | import org.jsonschema2dataclass.internal.compat.java.JavaPluginRegistration
12 | import org.jsonschema2dataclass.internal.defaultConfigurationSettings
13 | import org.jsonschema2dataclass.internal.js2p.Js2pProcessor
14 | import org.jsonschema2dataclass.internal.registrationTasksMachinery
15 | import org.jsonschema2dataclass.internal.task.DEFAULT_TARGET_FOLDER_BASE
16 | import org.jsonschema2dataclass.internal.task.JS2D_CONFIGURATION_NAME
17 | import org.jsonschema2dataclass.internal.task.JS2D_PLUGINS_CONFIGURATION_NAME
18 | import org.jsonschema2dataclass.internal.task.JS2P_EXTENSION_NAME
19 | import org.jsonschema2dataclass.internal.verifyExecutionNames
20 | import org.jsonschema2dataclass.internal.verifyExecutions
21 | import org.jsonschema2dataclass.internal.verifyGradleVersion
22 |
23 | private val processors: MutableList> = mutableListOf()
24 |
25 | @Suppress("unused")
26 | class Js2dPlugin : Plugin {
27 | private val javaPlugins = listOf("java", "java-library")
28 | private val androidPlugins = listOf("com.android.application", "com.android.library")
29 |
30 | override fun apply(project: Project) {
31 | verifyGradleVersion()
32 |
33 | val js2pExtension = project.extensions.create(JS2P_EXTENSION_NAME, Js2pExtension::class.java)
34 | js2pExtension.targetDirectoryPrefix.convention(project.layout.buildDirectory.dir(DEFAULT_TARGET_FOLDER_BASE))
35 |
36 | val js2dConfiguration = createConfiguration(project, JS2D_CONFIGURATION_NAME)
37 | val js2dConfigurationPlugins = createConfiguration(project, JS2D_PLUGINS_CONFIGURATION_NAME)
38 |
39 | verifyExecutionNames(js2pExtension.executions)
40 | verifyExecutions(project, js2pExtension.executions)
41 |
42 | val processor = obtainProcessor()
43 | processors.add(processor)
44 |
45 | processor.toolingMinimalDependencies(project, js2dConfiguration)
46 | processor.toolingMinimalDependencies(project, js2dConfigurationPlugins)
47 |
48 | for (pluginId in javaPlugins) {
49 | project.plugins.withId(pluginId) {
50 | project.apply()
51 | }
52 | }
53 | for (pluginId in androidPlugins) {
54 | project.plugins.withId(pluginId) {
55 | project.apply()
56 | }
57 | }
58 | }
59 | }
60 |
61 | internal class Js2pJavaPlugin : Plugin {
62 | override fun apply(project: Project) {
63 | applyPlugin(project, JavaPluginRegistration(), false)
64 | }
65 | }
66 |
67 | internal class Js2pAndroidPlugin : Plugin {
68 | override fun apply(project: Project) {
69 | applyPlugin(project, androidProcessorRegistrationSelector(), true)
70 | }
71 | }
72 |
73 | private fun applyPlugin(project: Project, registration: GradlePluginRegistration, disableGeneratedAnnotation: Boolean) {
74 | val js2pExtension = project.extensions.getByType(Js2pExtension::class.java)
75 |
76 | defaultConfigurationSettings(
77 | js2pExtension.executions,
78 | registration.defaultSchemaPath(project),
79 | disableGeneratedAnnotation,
80 | )
81 |
82 | val js2pProcessor: Js2pProcessor = processors.first() as Js2pProcessor
83 |
84 | registrationTasksMachinery(
85 | project,
86 | registration,
87 | js2pExtension.targetDirectoryPrefix,
88 | js2pExtension.executions,
89 | js2pProcessor,
90 | )
91 | }
92 |
93 | private fun createConfiguration(project: Project, name: String): Configuration {
94 | return project.configurations.maybeCreate(name).apply {
95 | isCanBeConsumed = false
96 | isCanBeResolved = true
97 | isVisible = true
98 | }
99 | }
100 |
101 | private fun obtainProcessor(): Js2dProcessor<*> = Js2pProcessor()
102 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/main/kotlin/org/jsonschema2dataclass/internal/Checks.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal
2 |
3 | import org.gradle.api.GradleException
4 | import org.gradle.api.InvalidUserDataException
5 | import org.gradle.api.Named
6 | import org.gradle.api.NamedDomainObjectContainer
7 | import org.gradle.api.Project
8 | import org.gradle.util.GradleVersion
9 | import org.jsonschema2dataclass.internal.task.PLUGIN_ID
10 |
11 | internal const val MINIMUM_GRADLE_VERSION = "6.0"
12 |
13 | /** Verify if gradle version is above minimum */
14 | internal fun verifyGradleVersion() {
15 | if (GradleVersion.current() < GradleVersion.version(MINIMUM_GRADLE_VERSION)) {
16 | throw GradleException(
17 | "Plugin $PLUGIN_ID requires at least Gradle $MINIMUM_GRADLE_VERSION, " +
18 | "but you are using ${GradleVersion.current().version}",
19 | )
20 | }
21 | }
22 |
23 | /** All execution names must be a valid identifiers as they are used as part of Gradle Task names */
24 | private val executionNameRegex = "[a-z][A-Za-z0-9_]*".toRegex()
25 |
26 | /** Verify if execution names are passing the regex */
27 | internal fun verifyExecutionNames(executions: NamedDomainObjectContainer) {
28 | executions.configureEach {
29 | if (!executionNameRegex.matches(name)) {
30 | throw InvalidUserDataException(
31 | "Plugin $PLUGIN_ID doesn't support execution name \"$name\" provided. " +
32 | "Please, rename to match regex \"$executionNameRegex\"",
33 | )
34 | }
35 | }
36 | }
37 |
38 | /** Error message if there's no executions defined */
39 | private const val ERROR_NO_EXECUTION =
40 | "No executions defined, behavior to with default execution has been removed " +
41 | "in plugin $PLUGIN_ID version 6.0.0. " +
42 | "Please, consider follow migration guide to upgrade plugin properly"
43 |
44 | /** Verify if executions are defined */
45 | internal fun verifyExecutions(project: Project, executions: NamedDomainObjectContainer) {
46 | project.afterEvaluate { // this can be reported only after evaluation
47 | if (executions.size == 0) {
48 | throw InvalidUserDataException(ERROR_NO_EXECUTION)
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/GradleVersions.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.js2p
2 |
3 | import org.gradle.api.JavaVersion
4 | import org.gradle.util.GradleVersion
5 | import org.junit.jupiter.params.provider.Arguments
6 |
7 | const val ENV_TEST_MIN = "TEST_GRADLE_VER_MIN"
8 | const val ENV_TEST_MAX = "TEST_GRADLE_VER_MAX"
9 | const val ENV_TEST_EXACT = "TEST_GRADLE_VER_EXACT"
10 | const val ENV_TEST_EXACT_CURRENT = "current"
11 |
12 | // Gradle releases can be found at https://gradle.org/releases/
13 | // M.B. current (Running) release will always be tested even it's not listed here.
14 | private val gradleReleases8x = arrayOf(
15 | "8.8",
16 | "8.7",
17 | "8.6",
18 | "8.5",
19 | "8.4",
20 | "8.3",
21 | "8.2.1",
22 | "8.1.1",
23 | "8.0.2",
24 | )
25 | private val gradleReleases7x = arrayOf(
26 | "7.6.4",
27 | "7.5.1",
28 | "7.4.2",
29 | "7.3.3",
30 | "7.2",
31 | "7.1.1",
32 | "7.0.2",
33 | )
34 | private val gradleReleases6x = arrayOf(
35 | "6.9.1",
36 | "6.8.3",
37 | "6.7.1",
38 | "6.6.1",
39 | "6.5.1",
40 | "6.4.1",
41 | "6.3",
42 | "6.2.2",
43 | "6.2.1",
44 | "6.1.1",
45 | "6.0.1",
46 | )
47 |
48 | private val gradleReleases = linkedSetOf(
49 | GradleVersion.current().version,
50 | *gradleReleases8x,
51 | *gradleReleases7x,
52 | *gradleReleases6x,
53 | )
54 |
55 | private val compatibleVersions = filterCompatibleVersions("6.0")
56 | private val compatibleVersionsConfigurationCache = filterCompatibleVersions("6.6")
57 |
58 | /**
59 | * Supported gradle versions per java
60 | *
61 | * Information can be found here: https://docs.gradle.org/current/userguide/compatibility.html
62 | * N.B. "Support for running Gradle" is the only thing is important
63 | *
64 | * | Java version | Gradle version |
65 | * |--------------|----------------|
66 | * | 1.8 - 13 | >= 6.0 |
67 | * | 14 | >= 6.3 |
68 | * | 15 | >= 6.7 |
69 | * | 16 | >= 7.0 |
70 | * | 17 | >= 7.3 |
71 | * | 18 | >= 7.5 |
72 | * | 19 | >= 7.6 |
73 | * | 20 | >= 8.3 |
74 | * | 21 | >= 8.5 |
75 | * | 22 | >= 8.8 |
76 | * | 22 | >= ?.? |
77 | * | other | not supported |
78 | */
79 | private fun gradleSupported(gradleVersion: ComparableGradleVersion): Boolean =
80 | when (JavaVersion.current()) {
81 | in JavaVersion.VERSION_1_8..JavaVersion.VERSION_13 -> gradleVersion >= 6 to 0
82 | JavaVersion.VERSION_14 -> gradleVersion >= 6 to 3
83 | JavaVersion.VERSION_15 -> gradleVersion >= 6 to 7
84 | JavaVersion.VERSION_16 -> gradleVersion >= 7 to 0
85 | JavaVersion.VERSION_17 -> gradleVersion >= 7 to 3
86 | JavaVersion.VERSION_18 -> gradleVersion >= 7 to 5
87 | JavaVersion.VERSION_19 -> gradleVersion >= 7 to 6
88 | JavaVersion.VERSION_20 -> gradleVersion >= 8 to 3
89 | JavaVersion.VERSION_21 -> gradleVersion >= 8 to 5
90 | JavaVersion.VERSION_22 -> gradleVersion >= 8 to 8
91 | else -> false // no official information on Gradle compatibility with further versions of Java
92 | }
93 |
94 | private fun filterCompatibleVersions(minimumInternalVersionString: String): List {
95 | val minimumInternalVersion = ComparableGradleVersion(minimumInternalVersionString)
96 |
97 | val minVersion = System.getenv()[ENV_TEST_MIN]?.let { ComparableGradleVersion(it) }
98 | val maxVersion = System.getenv()[ENV_TEST_MAX]?.let { ComparableGradleVersion(it) }
99 | val exactVersion = System.getenv()[ENV_TEST_EXACT]?.let {
100 | if (it == ENV_TEST_EXACT_CURRENT) {
101 | ComparableGradleVersion(GradleVersion.current().version)
102 | } else {
103 | ComparableGradleVersion(it)
104 | }
105 | }
106 |
107 | return gradleReleases
108 | .filter { v ->
109 | val version = ComparableGradleVersion(v)
110 |
111 | val supported = gradleSupported(version)
112 | val isAboveMinInternal = version >= minimumInternalVersion.gradleVersion
113 |
114 | val isAboveMin = minVersion?.let { version >= it.gradleVersion } ?: true
115 | val isBelowMax = maxVersion?.let { version <= it.gradleVersion } ?: true
116 | val isExact = exactVersion?.let { version.gradleVersion == it.gradleVersion } ?: true
117 |
118 | supported && isAboveMinInternal && isAboveMin && isBelowMax && isExact
119 | }
120 | .toList()
121 | }
122 |
123 | /**
124 | * Holder class for gradle releases version to test against current java
125 | * version
126 | */
127 | @Suppress("unused")
128 | class GradleVersions private constructor() {
129 | companion object {
130 | @JvmStatic
131 | private fun argumentFilter(compatibleVersions: List): List =
132 | if (compatibleVersions.isNotEmpty()) {
133 | compatibleVersions.map { Arguments.of(*arrayOf(it)) }
134 | } else {
135 | listOf(Arguments.of(*arrayOf(null)))
136 | }
137 |
138 | @JvmStatic
139 | fun gradleReleasesForTests(): List = argumentFilter(compatibleVersions)
140 |
141 | @JvmStatic
142 | fun configurationCacheCompatibleGradleReleasesForTests(): List =
143 | argumentFilter(compatibleVersionsConfigurationCache)
144 | }
145 | }
146 |
147 | private class ComparableGradleVersion(
148 | gradleVersionString: String,
149 | ) : Comparable> {
150 | val gradleVersion: Pair
151 |
152 | init {
153 | val gradleVersionParts = gradleVersionString.split(".")
154 | gradleVersion = if (gradleVersionParts.size >= 2) {
155 | gradleVersionParts[0].toInt() to gradleVersionParts[1].toInt()
156 | } else {
157 | gradleVersionParts[0].toInt() to 0
158 | }
159 | }
160 |
161 | override fun compareTo(other: Pair): Int {
162 | val resultFirst = this.gradleVersion.first.compareTo(other.first)
163 | if (resultFirst == 0) {
164 | return this.gradleVersion.second.compareTo(other.second)
165 | }
166 | return resultFirst
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/TestCasesGenerator.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.js2p
2 |
3 | import org.jsonschema2dataclass.internal.task.DEFAULT_TARGET_FOLDER_BASE
4 | import org.jsonschema2dataclass.internal.task.PLUGIN_ID
5 | import java.io.File
6 | import java.nio.file.Files
7 | import java.nio.file.Path
8 |
9 | const val TARGET_FOLDER_BASE_CUSTOM = DEFAULT_TARGET_FOLDER_BASE + "s"
10 | val BUILD_FILE_HEADER = """
11 | |plugins {
12 | | id "java-library"
13 | | id "$PLUGIN_ID" version "1.2.3"
14 | |}
15 | |repositories {
16 | | mavenCentral()
17 | |}
18 | |dependencies {
19 | | implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2"
20 | |}
21 | """.trimMargin()
22 |
23 | val BUILD_FILE_HEADER_PLUGIN_ONLY = """
24 | |plugins {
25 | | id "$PLUGIN_ID" version "1.2.3"
26 | |}
27 | """.trimMargin()
28 |
29 | val BUILD_FILE_HEADER_LAZY = """
30 | |plugins {
31 | | id "$PLUGIN_ID" version "1.2.3"
32 | |}
33 | |
34 | |// apply plugin: 'org.jsonschema2dataclass'
35 | |// Even though it is not recommended to use apply syntax, we use it here
36 | |// to ensure java-library plugin is applied after org.jsonschema2dataclass
37 | |apply plugin: 'java-library'
38 | |
39 | |repositories {
40 | | mavenCentral()
41 | |}
42 | |dependencies {
43 | | implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2"
44 | |}
45 | """.trimMargin()
46 |
47 | val ADDRESS_JSON = """
48 | |{
49 | | "description": "An Address following the convention of http://microformats.org/wiki/hcard",
50 | | "type": "object",
51 | | "properties": {
52 | | "post_office_box": { "type": "string" },
53 | | "extended_address": { "type": "string" },
54 | | "street_address": { "type": "string" },
55 | | "locality":{ "type": "string", "required": true },
56 | | "region": { "type": "string", "required": true },
57 | | "postal_code": { "type": "string" },
58 | | "country_name": { "type": "string", "required": true},
59 | | "address": {"type": "array", "items": "string"}
60 | | },
61 | | "dependencies": {
62 | | "post_office_box": "street_address",
63 | | "extended_address": "street_address"
64 | | }
65 | |}
66 | """.trimMargin()
67 |
68 | fun writeBuildFiles(
69 | testProjectDir: Path,
70 | shouldCopyAddressJSON: Boolean,
71 | suffix: String,
72 | buildFileHeader: String = BUILD_FILE_HEADER,
73 | ) {
74 | Files.write(
75 | testProjectDir.resolve("build.gradle"),
76 | (buildFileHeader + "\n" + suffix).trimIndent().toByteArray(),
77 | )
78 | Files.write(testProjectDir.resolve("settings.gradle"), ByteArray(0))
79 | if (shouldCopyAddressJSON) {
80 | copyAddressJSON(testProjectDir)
81 | }
82 | }
83 |
84 | fun createBuildFilesSingleSimple(testProjectDir: Path, shouldCopyAddressJSON: Boolean) {
85 | writeBuildFiles(
86 | testProjectDir,
87 | shouldCopyAddressJSON,
88 | """
89 | |jsonSchema2Pojo{
90 | | executions {
91 | | create("com") {
92 | | klass.targetPackage.set("com.example")
93 | | }
94 | | }
95 | |}
96 | """.trimMargin(),
97 | )
98 | }
99 |
100 | fun createBuildFilesSingleNoExtension(testProjectDir: Path, shouldCopyAddressJSON: Boolean) {
101 | writeBuildFiles(testProjectDir, shouldCopyAddressJSON, "")
102 | }
103 |
104 | /**
105 | * Multiple executions
106 | */
107 | fun createBuildFilesMultiple(testProjectDir: Path, shouldCopyAddressJSON: Boolean) {
108 | writeBuildFiles(
109 | testProjectDir,
110 | shouldCopyAddressJSON,
111 | """
112 | |jsonSchema2Pojo{
113 | | targetDirectoryPrefix = project.file("${'$'}{buildDir}/$TARGET_FOLDER_BASE_CUSTOM")
114 | | executions {
115 | | com{
116 | | klass.targetPackage = "com.example"
117 | | }
118 | | org{
119 | | klass.targetPackage = "org.example"
120 | | }
121 | | }
122 | |}
123 | """.trimMargin(),
124 | )
125 | }
126 |
127 | /**
128 | * Single with execution
129 | */
130 | fun createBuildFilesSingle(testProjectDir: Path, shouldCopyAddressJSON: Boolean) {
131 | writeBuildFiles(
132 | testProjectDir,
133 | shouldCopyAddressJSON,
134 | """
135 | |jsonSchema2Pojo {
136 | | executions {
137 | | com {
138 | | klass.targetPackage = "com.example"
139 | | }
140 | | }
141 | |}
142 | """.trimMargin(),
143 | )
144 | }
145 |
146 | /**
147 | * Single with execution, inherited
148 | */
149 | fun createBuildFilesLazyInit(testProjectDir: Path, shouldCopyAddressJSON: Boolean) {
150 | writeBuildFiles(
151 | testProjectDir,
152 | shouldCopyAddressJSON,
153 | suffix = """
154 | |jsonSchema2Pojo {
155 | | executions {
156 | | com {
157 | | klass.targetPackage = "com.example"
158 | | }
159 | | }
160 | |}
161 | """.trimMargin(),
162 | buildFileHeader = BUILD_FILE_HEADER_LAZY,
163 | )
164 | Files.write(testProjectDir.resolve("settings.gradle"), ByteArray(0))
165 | }
166 |
167 | internal fun copyAddressJSON(testProjectDir: Path) {
168 | val jsonDir = testProjectDir.resolve("src/main/resources/json")
169 | File(jsonDir.toString()).mkdirs()
170 | jsonDir.resolve("address.json").toFile().writeText(ADDRESS_JSON)
171 | }
172 |
173 | fun createBuildFilesWithSourcesJar(testProjectDir: Path) {
174 | writeBuildFiles(
175 | testProjectDir,
176 | true,
177 | """
178 | |jsonSchema2Pojo{
179 | | executions {
180 | | create("com") {
181 | | klass.targetPackage.set("com.example")
182 | | }
183 | | }
184 | |}
185 | |
186 | |java {
187 | | withSourcesJar()
188 | |}
189 | |
190 | |tasks.register("generateAndJarSources") {
191 | | dependsOn("generateJsonSchema2DataClass", "sourcesJar")
192 | |}
193 | """.trimMargin(),
194 | )
195 | }
196 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/TestUtils.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.js2p
2 |
3 | import org.gradle.testkit.runner.BuildTask
4 | import org.gradle.testkit.runner.GradleRunner
5 | import org.gradle.testkit.runner.TaskOutcome
6 | import org.jsonschema2dataclass.internal.task.JS2D_TASK_NAME
7 | import org.junit.jupiter.api.Assertions
8 | import org.junit.jupiter.api.Assertions.assertTrue
9 | import java.nio.file.Path
10 | import org.gradle.testkit.runner.BuildResult as BuildResultGradle
11 |
12 | internal const val COLON_TASK_NAME = ":$JS2D_TASK_NAME"
13 | internal const val COLON_TASK_NAME_FOR_COM = ":${JS2D_TASK_NAME}ConfigCom"
14 | internal const val COLON_TASK_NAME_FOR_ORG = ":${JS2D_TASK_NAME}ConfigOrg"
15 |
16 | fun createRunner(
17 | gradleVersion: String?,
18 | testProjectDir: Path,
19 | debug: Boolean = false,
20 | task: String = COLON_TASK_NAME,
21 | vararg arguments: String,
22 | ): GradleRunner =
23 | GradleRunner.create()
24 | .withDebug(debug)
25 | .withPluginClasspath()
26 | .withProjectDir(testProjectDir.toFile())
27 | .withArguments(task, *arguments).apply {
28 | if (gradleVersion != null) {
29 | withGradleVersion(gradleVersion)
30 | }
31 | }
32 |
33 | fun GradleRunner.execute(shouldFail: Boolean = false): BuildResult =
34 | BuildResult(
35 | projectDir = this.projectDir.toPath(),
36 | delegate = when (shouldFail) {
37 | true -> buildAndFail()
38 | false -> build()
39 | },
40 | )
41 |
42 | class BuildResult(val projectDir: Path, private val delegate: BuildResultGradle) : BuildResultGradle {
43 | override fun getOutput(): String = delegate.output
44 |
45 | override fun getTasks(): MutableList = delegate.tasks
46 |
47 | override fun tasks(outcome: TaskOutcome?): MutableList = delegate.tasks(outcome)
48 |
49 | override fun taskPaths(outcome: TaskOutcome?): MutableList = delegate.taskPaths(outcome)
50 |
51 | override fun task(taskPath: String?): BuildTask? = delegate.task(taskPath)
52 | }
53 |
54 | fun BuildResult.assertResultAndGeneratedClass(
55 | taskName: String = COLON_TASK_NAME_FOR_COM,
56 | targetFolder: String = TARGET_FOLDER_DEFAULT,
57 | ): BuildResult {
58 | Assertions.assertEquals(TaskOutcome.SUCCESS, task(taskName)?.outcome, "task $taskName is successful")
59 |
60 | addressJavaExists(projectDir, targetFolder, taskToExecution[taskName]!!, taskToPackage[taskName]!!)
61 |
62 | return this
63 | }
64 |
65 | private val taskToExecution = mapOf(
66 | COLON_TASK_NAME_FOR_COM to EXECUTION_NAME_COM,
67 | COLON_TASK_NAME_FOR_ORG to EXECUTION_NAME_ORG,
68 | )
69 |
70 | private val taskToPackage = mapOf(
71 | COLON_TASK_NAME_FOR_COM to PACKAGE_COM_EXAMPLE,
72 | COLON_TASK_NAME_FOR_ORG to PACKAGE_ORG_EXAMPLE,
73 | )
74 |
75 | fun addressJavaExists(testProjectDir: Path, targetDirectoryPrefix: String, executionName: String, subfolder: String) {
76 | val js2pDir = testProjectDir.resolve(targetDirectoryPrefix).resolve(executionName).resolve(subfolder)
77 | assertTrue(js2pDir.toFile().exists())
78 | assertTrue(js2pDir.resolve("Address.java").toFile().exists())
79 | }
80 |
--------------------------------------------------------------------------------
/plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/internal/NameGeneratorTest.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.js2p.internal
2 |
3 | import org.jsonschema2dataclass.internal.createTaskNameDescription
4 | import org.jsonschema2dataclass.internal.generatePart
5 | import org.junit.jupiter.api.Assertions.assertEquals
6 | import org.junit.jupiter.params.ParameterizedTest
7 | import org.junit.jupiter.params.provider.CsvSource
8 |
9 | private const val EXECUTION_NAME = "execution"
10 |
11 | class NameGeneratorTest {
12 | @ParameterizedTest
13 | @CsvSource(
14 | "variant,release,true,ForRelease,'for variant release'",
15 | "flavor,release,true,ForRelease,'for flavor release'",
16 | "variant,release,false,ForVariantRelease,'for variant release'",
17 | "flavor,release,false,ForFlavorRelease,'for flavor release'",
18 | )
19 | fun generatePartTest(
20 | suffixName: String,
21 | suffixValue: String,
22 | compatible: Boolean,
23 | expectedName: String,
24 | expectedDescription: String,
25 | ) {
26 | val suffix = suffixName to suffixValue
27 | val actual = generatePart(suffix, compatible)
28 | assertEquals(expectedName to expectedDescription, actual)
29 | }
30 |
31 | @ParameterizedTest
32 | @CsvSource(
33 | "Js2p,'tool description',,,,,true," +
34 | "generateJsonSchema2DataClassConfigExecution," +
35 | "'tool description for configuration execution'",
36 | "Js2p,'tool description',,,,,false," +
37 | "generateJsonSchema2DataClassJs2pConfigExecution," +
38 | "'tool description for configuration execution'",
39 | "Js2p,'tool description',variant,release,,,true," +
40 | "generateJsonSchema2DataClassForReleaseConfigExecution," +
41 | "'tool description for variant release for configuration execution'",
42 | "Js2p,'tool description',variant,release,,,false," +
43 | "generateJsonSchema2DataClassJs2pForVariantReleaseConfigExecution," +
44 | "'tool description for variant release for configuration execution'",
45 | "Js2p,'tool description',variant,release,flavor,shop,true," +
46 | "generateJsonSchema2DataClassForVariantReleaseForFlavorShopConfigExecution," +
47 | "'tool description for variant release for flavor shop for configuration execution'",
48 | "Js2p,'tool description',variant,release,flavor,shop,false," +
49 | "generateJsonSchema2DataClassJs2pForVariantReleaseForFlavorShopConfigExecution," +
50 | "'tool description for variant release for flavor shop for configuration execution'",
51 | "Js2d,'tool description',,,,,true," +
52 | "generateJsonSchema2DataClassJs2dConfigExecution," +
53 | "'tool description for configuration execution'",
54 | "Js2d,'tool description',,,,,false," +
55 | "generateJsonSchema2DataClassJs2dConfigExecution," +
56 | "'tool description for configuration execution'",
57 | "Js2d,'tool description',variant,release,,,true," +
58 | "generateJsonSchema2DataClassJs2dForReleaseConfigExecution," +
59 | "'tool description for variant release for configuration execution'",
60 | "Js2d,'tool description',variant,release,,,false," +
61 | "generateJsonSchema2DataClassJs2dForVariantReleaseConfigExecution," +
62 | "'tool description for variant release for configuration execution'",
63 | "Js2d,'tool description',variant,release,flavor,shop,true," +
64 | "generateJsonSchema2DataClassJs2dForVariantReleaseForFlavorShopConfigExecution," +
65 | "'tool description for variant release for flavor shop for configuration execution'",
66 | "Js2d,'tool description',variant,release,flavor,shop,false," +
67 | "generateJsonSchema2DataClassJs2dForVariantReleaseForFlavorShopConfigExecution," +
68 | "'tool description for variant release for flavor shop for configuration execution'",
69 | )
70 | fun generateSuffixesTest(
71 | toolName: String,
72 | toolDescription: String,
73 | suffix1Name: String?,
74 | suffix1Value: String?,
75 | suffix2Name: String?,
76 | suffix2Value: String?,
77 | compatible: Boolean,
78 | expectedName: String,
79 | expectedDescription: String,
80 | ) {
81 | val pairs = mutableListOf>()
82 |
83 | if (suffix1Name != null && suffix1Value != null) {
84 | pairs.add(suffix1Name to suffix1Value)
85 | }
86 | if (suffix2Name != null && suffix2Value != null) {
87 | pairs.add(suffix2Name to suffix2Value)
88 | }
89 | val suffixes = pairs.toMap()
90 |
91 | val tool = toolName to toolDescription
92 |
93 | val result = createTaskNameDescription(
94 | EXECUTION_NAME,
95 | suffixes,
96 | compatible,
97 | tool,
98 | )
99 | val expected = expectedName to expectedDescription
100 | assertEquals(expected, result)
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl-base`
3 | id("org.jsonschema2dataclass.internal.library")
4 | id("org.jsonschema2dataclass.internal.processor-version")
5 | }
6 |
7 | base.archivesName.set("jsonschema2dataclass-processor-jsonschema2pojo")
8 | description = "Jsonschema2pojo schema processor compatibility layer: Compatibility layer for Jsonschema2pojo processor."
9 |
10 | processorVersion {
11 | library.set("jsonschema2pojo")
12 | }
13 |
14 | dependencies {
15 | compileOnly(processors.jsonschema2pojo)
16 | implementation(projects.pluginGradle.compat.kotlin)
17 | implementation(projects.pluginGradle.common)
18 |
19 | testImplementation(libs.bundles.junit.tests)
20 | testRuntimeOnly(libs.bundles.junit.runtime)
21 | testImplementation(gradleTestKit())
22 |
23 | testImplementation(processors.jsonschema2pojo)
24 | }
25 |
26 | tasks.test {
27 | useJUnitPlatform()
28 | systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_method")
29 | systemProperty("junit.jupiter.execution.parallel.enabled", "true")
30 | }
31 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pGenerationTask.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.js2p
2 |
3 | import org.gradle.api.tasks.CacheableTask
4 | import org.gradle.workers.WorkQueue
5 | import org.gradle.workers.WorkerExecutor
6 | import org.jsonschema2dataclass.ext.Js2pConfiguration
7 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase
8 | import javax.inject.Inject
9 |
10 | @CacheableTask
11 | internal abstract class Js2pGenerationTask @Inject constructor(
12 | workerExecutor: WorkerExecutor,
13 | ) : Js2dGeneratorTaskBase(workerExecutor) {
14 | override fun submit(workQueue: WorkQueue) {
15 | val js2pConfig = Js2pWorkerConfig.fromConfig(uuid, targetDirectory.asFile.get(), configuration)
16 | workQueue.submit(Js2pWorker::class.java) {
17 | config = js2pConfig
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pProcessor.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.js2p
2 |
3 | import org.gradle.api.GradleException
4 | import org.gradle.api.Project
5 | import org.gradle.api.artifacts.Configuration
6 | import org.jsonschema2dataclass.ext.Js2pConfiguration
7 | import org.jsonschema2dataclass.internal.Js2dProcessor
8 | import org.jsonschema2dataclass.internal.task.JS2P_TOOL_NAME
9 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase
10 | import java.util.Properties
11 | import java.util.concurrent.atomic.AtomicReference
12 | import java.util.concurrent.locks.ReentrantLock
13 |
14 | private const val JS2P_TASK_DESCRIPTION = "Generates Java models from a json schema using jsonschema2pojo"
15 |
16 | private const val RESOURCE_FILE = "processor.properties"
17 | private const val PROPERTY = "processor"
18 |
19 | private val JS2PVersion = AtomicReference(null)
20 | private val readLock = ReentrantLock()
21 |
22 | class Js2pProcessor : Js2dProcessor {
23 | private fun readVersion(): String {
24 | if (JS2PVersion.get() != null) {
25 | return JS2PVersion.get()!!
26 | }
27 | readLock.lock()
28 | try {
29 | if (JS2PVersion.get() != null) {
30 | return JS2PVersion.get()!!
31 | }
32 | val stream =
33 | Js2pProcessor::class.java
34 | .classLoader
35 | .getResourceAsStream(RESOURCE_FILE)
36 | if (stream == null) {
37 | throw GradleException("jsonschema2pojo processor version must be provided")
38 | }
39 | val props = Properties()
40 | stream.use {
41 | props.load(it)
42 | }
43 | JS2PVersion.compareAndSet(null, props[PROPERTY].toString())
44 | } finally {
45 | readLock.unlock()
46 | }
47 |
48 | if (JS2PVersion.get() == null) {
49 | throw GradleException("jsonschema2pojo processor version must be provided")
50 | }
51 | return JS2PVersion.get()!!
52 | }
53 |
54 | override fun toolNameForTask(): Pair = JS2P_TOOL_NAME to JS2P_TASK_DESCRIPTION
55 |
56 | override fun generatorTaskClass(): Class> =
57 | Js2pGenerationTask::class.java
58 |
59 | override fun toolingMinimalDependencies(project: Project, configuration: Configuration) {
60 | val version = readVersion()
61 |
62 | configuration.defaultDependencies {
63 | add(project.dependencies.create(version))
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pWorker.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.js2p
2 |
3 | import org.gradle.api.logging.Logger
4 | import org.gradle.api.logging.Logging
5 | import org.gradle.workers.WorkAction
6 | import org.gradle.workers.WorkParameters
7 | import org.jsonschema2pojo.Jsonschema2Pojo
8 | import org.jsonschema2pojo.RuleLogger
9 |
10 | internal abstract class Js2pWorker : WorkAction {
11 | override fun execute() {
12 | val config = Js2pConfig(
13 | parameters.config.targetDirectory,
14 | parameters.config.io,
15 | parameters.config.klass,
16 | parameters.config.constructors,
17 | parameters.config.methods,
18 | parameters.config.fields,
19 | parameters.config.dateTime,
20 | )
21 | val ruleLogAdapter = GradleRuleLogAdapter(Logging.getLogger(this.javaClass))
22 | if (ruleLogAdapter.isTraceEnabled) {
23 | ruleLogAdapter.trace("[{}] Using this configuration:\n{}", parameters.config.uuid, config)
24 | }
25 |
26 | Jsonschema2Pojo.generate(config, ruleLogAdapter)
27 | }
28 | }
29 |
30 | internal interface Js2pWorkerParams : WorkParameters {
31 | var config: Js2pWorkerConfig
32 | }
33 |
34 | internal class GradleRuleLogAdapter constructor(
35 | private val logger: Logger,
36 | ) : RuleLogger {
37 | override fun isDebugEnabled(): Boolean =
38 | logger.isDebugEnabled
39 |
40 | override fun isErrorEnabled(): Boolean =
41 | logger.isErrorEnabled
42 |
43 | override fun isInfoEnabled(): Boolean =
44 | logger.isInfoEnabled
45 |
46 | override fun isTraceEnabled(): Boolean =
47 | logger.isTraceEnabled
48 |
49 | override fun isWarnEnabled(): Boolean =
50 | logger.isWarnEnabled
51 |
52 | override fun debug(msg: String?) {
53 | logger.debug(msg)
54 | }
55 |
56 | override fun error(msg: String?) {
57 | logger.debug(msg)
58 | }
59 |
60 | override fun error(msg: String?, e: Throwable?) {
61 | logger.error(msg, e)
62 | }
63 |
64 | override fun info(msg: String?) {
65 | logger.info(msg)
66 | }
67 |
68 | override fun trace(msg: String?) {
69 | logger.trace(msg)
70 | }
71 |
72 | fun trace(msg: String?, arg: Any, arg2: Any) {
73 | logger.trace(msg, arg, arg2)
74 | }
75 |
76 | override fun warn(msg: String?, e: Throwable?) {
77 | logger.warn(msg, e)
78 | }
79 |
80 | override fun warn(msg: String?) {
81 | logger.debug(msg)
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/Randomizer.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal
2 |
3 | private val random = java.security.SecureRandom() // should we use .asKotlinRandom() here?
4 | private val alphaNumeric = ('a'..'z') + ('A'..'Z') + ('0'..'9')
5 |
6 | /**
7 | * Return random value from list
8 | */
9 | fun randomValueFromList(values: List): T = values[random.nextInt(values.size)]
10 |
11 | /**
12 | * Return random value from an enum
13 | */
14 | inline fun > randomEnum(): T = randomValueFromList(enumValues().asList())
15 |
16 | /**
17 | * Return random alphanumeric list with length (1..11)
18 | */
19 | fun randomString(len: Int = 10): String =
20 | List(random.nextInt(len) + 1) { randomValueFromList(alphaNumeric) }.joinToString("")
21 |
22 | /**
23 | * Create a random list with random size (0..10) and values with random len (1..11)
24 | */
25 | fun randomList(size: Int = 10, len: Int = 10) = List(random.nextInt(size)) { randomString(len) }
26 |
27 | /**
28 | * Create a random set with random size (0..10) and values with random len (1..11)
29 | */
30 | fun randomSet(size: Int = 10, len: Int = 10) = randomList(size, len).toSet()
31 |
32 | /**
33 | * Create a random set with random size (0..10) and keys and values with random len (1..11)
34 | */
35 | fun randomMap(size: Int = 10, len: Int = 10) =
36 | List(random.nextInt(size)) { randomString(len) to randomString(len) }.toMap()
37 |
38 | /**
39 | * Return random boolean.
40 | */
41 | fun randomBoolean() = random.nextBoolean()
42 |
43 | /**
44 | * Convert value to null randomly
45 | */
46 | fun nullable(value: T): T? = if (randomBoolean()) null else value
47 |
--------------------------------------------------------------------------------
/plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/js2p/WorkerConvertTest.kt:
--------------------------------------------------------------------------------
1 | package org.jsonschema2dataclass.internal.js2p
2 |
3 | import org.gradle.testfixtures.ProjectBuilder
4 | import org.jsonschema2dataclass.ext.Js2pConfiguration
5 | import org.junit.jupiter.api.DisplayName
6 | import org.junit.jupiter.api.RepeatedTest
7 | import org.junit.jupiter.api.assertAll
8 | import java.io.File
9 | import java.util.UUID
10 |
11 | private const val CONFIGURATION_NAME = "random_configuration"
12 |
13 | class WorkerConvertTest {
14 | @RepeatedTest(100)
15 | @DisplayName("single execution")
16 | fun testExtensionConversions() {
17 | // create and randomize extension,
18 | val project = ProjectBuilder.builder().build()
19 | val configuration = randomize(
20 | project.extensions.create(
21 | CONFIGURATION_NAME,
22 | Js2pConfiguration::class.java,
23 | "name",
24 | ),
25 | )
26 | // convert to an intermediate configuration
27 | val newConfiguration = Js2pWorkerConfig.fromConfig(UUID.randomUUID(), File("/"), configuration)
28 |
29 | // generate "default" config
30 | val simpleConfig = randomizeGenerationConfig()
31 | // create a target configuration
32 | val js2pConfig = Js2pConfig(
33 | File("/"),
34 | newConfiguration.io,
35 | newConfiguration.klass,
36 | newConfiguration.constructors,
37 | newConfiguration.methods,
38 | newConfiguration.fields,
39 | newConfiguration.dateTime,
40 | simpleConfig,
41 | )
42 | // test if all conversions are correct
43 | assertAll(
44 | { checkIfEqual(configuration, newConfiguration) },
45 | { checkIfEqual(configuration, js2pConfig, simpleConfig) },
46 | )
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "JsonSchema2DataClass"
2 |
3 | pluginManagement {
4 | includeBuild("internal")
5 | }
6 |
7 | plugins {
8 | id("com.gradle.develocity") version "4.0.1"
9 | id("org.jsonschema2dataclass.internal.settings-develocity")
10 | }
11 |
12 | enableFeaturePreviewQuietly("TYPESAFE_PROJECT_ACCESSORS", "Type-safe project accessors")
13 |
14 | // Main plugin
15 | include(":plugin-gradle:plugin")
16 | // common interfaces
17 | include(":plugin-gradle:common")
18 |
19 | // Kotlin language compatibility along Gradle versions
20 | include(":plugin-gradle:compat:kotlin")
21 | // Gradle plugin compatibility
22 | include(":plugin-gradle:compat:android")
23 | include(":plugin-gradle:compat:agp34")
24 | include(":plugin-gradle:compat:java")
25 |
26 | include(":plugin-gradle:compat:agp7")
27 |
28 | // processors:
29 | include(":plugin-gradle:processors:jsonschema2pojo")
30 |
31 | @Suppress("UnstableApiUsage")
32 | dependencyResolutionManagement {
33 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
34 | repositories {
35 | google().content {
36 | includeGroup("com.android")
37 | includeGroup("android.arch.lifecycle")
38 | includeGroup("android.arch.core")
39 | includeGroupByRegex("com\\.android\\..*")
40 | includeGroupByRegex("com\\.google\\..*")
41 | includeGroupByRegex("androidx\\..*")
42 | }
43 | mavenCentral()
44 | }
45 | versionCatalogs {
46 | create("agp") {
47 | from(files("gradle/agp.dependencies.toml"))
48 | }
49 | create("libs") {
50 | from(files("gradle/libs.dependencies.toml"))
51 | }
52 | create("processors") {
53 | from(files("gradle/processors.toml"))
54 | }
55 | create("pluginDeps") {
56 | from(files("gradle/plugins.dependencies.toml"))
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------