Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generators): use version catalog #329

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/plugin-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- nx-gradle micronaut e2e
- nx-gradle micronaut kotlin dsl e2e
- nx-gradle all e2e
- nx-gradle version-catalog e2e
- nx-gradle all kotlin dsl e2e
- nx-gradle quarkus e2e
- nx-gradle quarkus kotlin dsl e2e
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[versions]
java = "<%= javaVersion %>"
kotlin = "<%= kotlinVersion %>"
agp = "<%= agpVersion %>"
compose = "<%= composeVersion %>"
ktlint = "<%= ktlintVersion %>"

[libraries]

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose" }
github-khalilou88-jnxplus = { id = "io.github.khalilou88.jnxplus", version.ref = "<%= jnxplusGradlePluginVersion %>" }

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[versions]

[libraries]

[plugins]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[versions]

[libraries]

[plugins]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[versions]

[libraries]

[plugins]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[versions]
java = "<%= javaVersion %>"
kotlin = "<%= kotlinVersion %>"
boot = "<%= springBootVersion %>"

[libraries]

[plugins]
springframework-boot = { id = "org.springframework.boot", version.ref = "boot" }
spring-dependency-management = { id = "io.spring.dependency-management", version = "1.1.0" }
github-khalilou88-jnxplus = { id = "io.github.khalilou88.jnxplus", version = "0.2.0" }
jetbrains-kotlin-plugin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ android.minSdk=24

#Versions
javaVersion=<%= javaVersion %>
kotlin.version=1.8.20
agp.version=7.4.2
compose.version=1.4.1
kotlin.version=<%= kotlinVersion %>
agp.version=<%= agpVersion %>
compose.version=<%= composeVersion %>
jnxplusGradlePluginVersion=<%= jnxplusGradlePluginVersion %>


Expand Down
9 changes: 9 additions & 0 deletions packages/nx-gradle/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ function addFiles(tree: Tree, options: NormalizedSchema) {
options.gradleRootDirectory,
templateOptions,
);

if (options.versionManagement === 'version-catalog') {
generateFiles(
tree,
path.join(__dirname, 'files', 'gradle', 'catalog', options.preset),
'gradle',
templateOptions
);
}
}

export default initGenerator;
Expand Down
1 change: 1 addition & 0 deletions packages/nx-gradle/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface NxGradleInitGeneratorSchema {
gradleRootDirectory: string;
preset: PresetType;
skipWrapper?: boolean;
versionManagement: 'properties' | 'version-catalog';
}
22 changes: 21 additions & 1 deletion packages/nx-gradle/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,33 @@
"description": "Don't generate Gradle Wrapper",
"type": "boolean",
"default": false
},
"versionManagement": {
"description": "Version management",
"type": "string",
"default": "properties",
"x-prompt": {
"message": "Which version management would you like to use?",
"type": "list",
"items": [
{
"value": "properties",
"label": "use gradle properties"
},
{
"value": "version-catalog",
"label": "use version catalog"
}
]
}
}
},
"required": [
"javaVersion",
"dsl",
"rootProjectName",
"gradleRootDirectory",
"preset"
"preset",
"versionManagement"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
addTmpToGitignore,
createTestWorkspace,
removeTmpFromGitignore,
} from '@jnxplus/internal/testing';
import {
checkFilesExist,
readJson,
runNxCommandAsync,
uniq,
} from '@nx/plugin/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs';

describe('nx-gradle version-catalog e2e', () => {
let workspaceDirectory: string;
const isCI =
process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
const rootProjectName = uniq('root-project-');

beforeAll(async () => {
workspaceDirectory = createTestWorkspace();

// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(`npm install -D @jnxplus/nx-gradle@e2e`, {
cwd: workspaceDirectory,
stdio: 'inherit',
env: process.env,
});

await runNxCommandAsync(
`generate @jnxplus/nx-gradle:init --dsl kotlin --rootProjectName ${rootProjectName} --preset spring-boot --versionManagement version-catalog`,
);

if (isCI) {
removeTmpFromGitignore();
}
}, 120000);

afterAll(async () => {
if (isCI) {
addTmpToGitignore();
}
// Cleanup the test project
rmSync(workspaceDirectory, {
recursive: true,
force: true,
});
});

it('should set NX_VERBOSE_LOGGING to true', async () => {
expect(process.env['NX_VERBOSE_LOGGING']).toBe('true');
}, 120000);

it('should use dsl option when initiating the workspace', async () => {
// Making sure the package.json file contains the @jnxplus/nx-gradle dependency
const packageJson = readJson('package.json');
expect(packageJson.devDependencies['@jnxplus/nx-gradle']).toBeTruthy();

// Making sure the nx.json file contains the @jnxplus/nx-gradle inside the plugins section
const nxJson = readJson('nx.json');
expect(nxJson.plugins.includes('@jnxplus/nx-gradle')).toBeTruthy();

expect(() =>
checkFilesExist(
'gradle/wrapper/gradle-wrapper.jar',
'gradle/wrapper/gradle-wrapper.properties',
'gradlew',
'gradlew.bat',
'gradle.properties',
'settings.gradle.kts',
'tools/linters/checkstyle.xml',
),
).not.toThrow();
}, 120000);

it('shoud works', async () => {
const name = uniq('app-');

await runNxCommandAsync(`generate @jnxplus/nx-gradle:app ${name}`);
}, 240000);
});