This is an automated email from the ASF dual-hosted git repository. danwatford pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 6caa74cd7e Implemented: Use node/npm during gradle build from multiple sub-projects (OFBIZ-12789) 6caa74cd7e is described below commit 6caa74cd7e7fc06924e0d93cfd7adfce471e3e4f Author: Daniel Watford <dan...@watfordconsulting.com> AuthorDate: Thu Apr 13 21:23:08 2023 +0100 Implemented: Use node/npm during gradle build from multiple sub-projects (OFBIZ-12789) Added gradle plugin, ofbiz-node-conventions, to set conventional use of the gradle node plugin across OFBiz sub-projects (i.e. components). Modified common-theme to install and cleanup NPM modules at appropriate points in the gradle task lifecycle. This change will allow multiple components, including plugsin, to leverage the gradle node plugin in their build process without needing updates to the parent build.gradle script. --- .dockerignore | 3 +- Dockerfile | 1 + build.gradle | 30 +--------- buildSrc/build.gradle | 22 +++++++ .../src/main/groovy/ofbiz-node-conventions.gradle | 70 ++++++++++++++++++++++ themes/common-theme/build.gradle | 26 ++++++++ .../webapp/common-theme/js/package-lock.json | 4 +- 7 files changed, 124 insertions(+), 32 deletions(-) diff --git a/.dockerignore b/.dockerignore index 24f2d41429..521ad04c5d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -27,4 +27,5 @@ Dockerfile /plugins/.svn /plugins/.github /plugins/.git - +/buildSrc/.gradle +/buildSrc/build diff --git a/Dockerfile b/Dockerfile index 23d7470c7e..b67d18d22b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,7 @@ RUN --mount=type=cache,id=gradle-cache,sharing=locked,target=/root/.gradle \ ["./gradlew", "--console", "plain"] # Copy all OFBiz sources. +COPY buildSrc/ buildSrc/ COPY applications/ applications/ COPY config/ config/ COPY framework/ framework/ diff --git a/build.gradle b/build.gradle index d3f580529c..b47a26e4ed 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ plugins { id 'com.github.ben-manes.versions' version '0.42.0' apply false id "com.github.ManifestClasspath" version "0.1.0-RELEASE" id "com.github.jakemarsden.git-hooks" version "0.0.2" - id "com.github.node-gradle.node" version "3.5.0" + id "com.github.node-gradle.node" version '3.5.1' apply false } /* OWASP plugin @@ -113,27 +113,6 @@ javadoc { } } -node { - download = true - version = '16.13.1' - // npmVersion will be the one that comes default with node - - // https://github.com/node-gradle/gradle-node-plugin/blob/2.2.4/README.md - // Set the work directory where node_modules should be located - nodeModulesDir = file("${project.projectDir}/themes/common-theme/webapp/common-theme/js") - // If you set a "CI" env var then ci only will be used: - // https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md#how-do-i-use-npm-ci-instead-of-npm-install - npmInstallCommand = System.getenv('CI') ? 'ci' : 'install' -} - -tasks.getByName("distTar") { - dependsOn "npmInstall" -} - -tasks.getByName("distZip") { - dependsOn "npmInstall" -} - java { sourceCompatibility(JavaVersion.VERSION_17) targetCompatibility(JavaVersion.VERSION_17) @@ -147,8 +126,6 @@ tasks.withType(JavaCompile) { // Exclude varargs warnings which are not silenced by @SafeVarargs. options.compilerArgs << '-Xlint:-varargs' } - // Executes on each compilation so that if dependencies are not downloaded yet or some new dependencies are added they get automatically downloaded - if (!project.hasProperty('skipNpmInstall')) finalizedBy 'npmInstall' } // Only used for release branches @@ -1085,11 +1062,6 @@ task cleanFooterFiles(group: cleanupGroup, description: 'clean generated footer delete gitFooterFile } } -task cleanNpm(group: cleanupGroup, description: 'clean node modules') { - doLast { - delete "${project.projectDir}/themes/common-theme/webapp/common-theme/js/node_modules" - } -} /* * Keep this task below all other clean tasks The location of * declaration is important because it means that it will automatically diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000000..e27ac17318 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id 'groovy-gradle-plugin' +} diff --git a/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle b/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle new file mode 100644 index 0000000000..6e5d707748 --- /dev/null +++ b/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * This plugin defines usage of the node-gradle plugin for OFBiz sub-projects. + * + * NPM Install (or ci) will be run as a dependency of the classes task. The output from NPM Install will be cleaned + * up as part of the parent project's cleanAll task. + * + * Sub projects should apply this plugin and then configure the node block with the path to the directory containing + * the package.json file. Example: + * + * plugins { + * id 'ofbiz-node-conventions' + * } + * + * node { + * nodeProjectDir = file('webapp/common-theme/js') + * } + */ + +plugins { + id 'base' // Provides the clean<TaskName> rule for the cleanNpmInstall task. + id 'com.github.node-gradle.node' +} + +node { + download = true + version = "16.13.1" + + // If environment variable CI is set, use 'npm ci' instead of 'npm install' to populate node_modules. + npmInstallCommand = System.getenv("CI") ? 'ci' : 'install' +} + +// Pull NPM dependencies when the classes task is run. +// Hooking into classes ensures that dependencies are available if OFBiz is +// started via the Gradle Application Plugin's run task, or if a distribution +// is being built (distTar, distZip, etc.). +if (!project.rootProject.hasProperty('skipNpmInstall')) { + project.rootProject.tasks.getByName('classes').dependsOn npmInstall +} + +// Task to clean up the output from npmInstall. +task cleanNpm(group: 'Cleaning', description: 'Clean installed node modules') { + dependsOn cleanNpmInstall +} + +// Hook into the root project's cleanAll task to clean up the output from the +// npmInstall task. +project.rootProject.tasks.whenTaskAdded { task -> + if (task.name == 'cleanAll') { + task.dependsOn cleanNpmInstall + } +} diff --git a/themes/common-theme/build.gradle b/themes/common-theme/build.gradle new file mode 100644 index 0000000000..2e58284a50 --- /dev/null +++ b/themes/common-theme/build.gradle @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id 'ofbiz-node-conventions' +} + +node { + nodeProjectDir = file('webapp/common-theme/js') +} diff --git a/themes/common-theme/webapp/common-theme/js/package-lock.json b/themes/common-theme/webapp/common-theme/js/package-lock.json index 49d84af2e3..791aa83676 100644 --- a/themes/common-theme/webapp/common-theme/js/package-lock.json +++ b/themes/common-theme/webapp/common-theme/js/package-lock.json @@ -81,7 +81,7 @@ "node_modules/jquery.browser": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/jquery.browser/-/jquery.browser-0.1.0.tgz", - "integrity": "sha1-nHKmCV/SgUtER26o9xZne3Kmors=", + "integrity": "sha512-5GjtLzzEBzxs/nwSVpCbSdk0acssfKsP7Upp43zmdHVV1Vb6E9VayyqPAQlfLrTeZL3YSWocCbkOvKdAc2CN4g==", "engines": { "node": ">= 0.4.0" } @@ -160,7 +160,7 @@ "jquery.browser": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/jquery.browser/-/jquery.browser-0.1.0.tgz", - "integrity": "sha1-nHKmCV/SgUtER26o9xZne3Kmors=" + "integrity": "sha512-5GjtLzzEBzxs/nwSVpCbSdk0acssfKsP7Upp43zmdHVV1Vb6E9VayyqPAQlfLrTeZL3YSWocCbkOvKdAc2CN4g==" }, "trumbowyg": { "version": "2.27.3",