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

update documentation based on return to buildscript{} #922

Merged
merged 2 commits into from
Nov 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/en/guide/commandLine/gradleBuild/gradlePlugins.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When you create a new project with the link:../ref/Command%20Line/create-app.html[create-app] command, a default `settings.gradle`, `buildSrc` and `build.gradle` is created. The default `build.gradle` configures the build with a set of Gradle plugins that allow Gradle to build the Grails project:
When you create a new project with the link:../ref/Command%20Line/create-app.html[create-app] command, a default `build.gradle` is created. The default `build.gradle` configures the build with a set of Gradle plugins that allow Gradle to build the Grails project:

[source,groovy]
----
Expand Down
161 changes: 0 additions & 161 deletions src/en/guide/upgrading/upgrading50x.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,169 +144,8 @@ plugins {
}
```


By migrating to the `plugins` block, your Grails 6 project will adhere to modern Gradle conventions, making it easier to manage plugin dependencies and configurations. This new approach maintains consistency and enhances the overall structure of the project, ensuring a smoother and more efficient development process.

##### 6.2. Use the pluginManagement Block

Moving from `apply plugin` in the `build.gradle` file to the `pluginManagement` block in the `settings.gradle` file is a significant change introduced in Grails 6. This change is part of Grails' effort to adopt the Gradle `pluginManagement` approach for better plugin version control and consistency across projects.

In the previous versions of Grails (before Grails 6), developers used to apply plugins directly in the `build.gradle` file using the `apply plugin` syntax. For example:

.build.gradle
```groovy
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
classpath "org.grails.plugins:hibernate5:7.3.0"
classpath "org.grails.plugins:views-gradle:2.3.2"
}
}

version "0.1"
group "hellorestapi"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.plugins.views-json"
```


However, with Grails 6, the recommended practice is to move plugin declarations to the `pluginManagement` block in the `settings.gradle` file. The `pluginManagement` block acts as a central place to manage plugin versions for all projects within a multi-project build.

**Configuring Plugins in the pluginManagement Block:**

Here's how you can declare the `views-json` plugin in the `pluginManagement` block:

1. Open the `settings.gradle` file in your Grails 6 project.

2. Add the `pluginManagement` block with the `views-json` plugin declaration:

.settings.gradle
```groovy
pluginManagement {
repositories {
// Add the Grails plugin repository to resolve the views-json plugin
maven { url "https://repo.grails.org/grails/core" }
// Other repositories can be added here if needed
}

// Declare the views-json plugin and its version
plugins {
id 'org.grails.plugins.views-json' version '3.0.0'
// Other plugins can be declared here
}
}
```


By including the `views-json` plugin in the `pluginManagement` block, Grails 6 will ensure that all projects within the multi-project build use the specified version of the `views-json` plugin. This promotes consistency in JSON rendering across different projects and simplifies maintenance and version control.

**Moving Older Applications to the New Approach:**

If you are migrating an older Grails application to Grails 6, you can update the plugin declarations from `apply plugin` to the `plugins` block in the `build.gradle` file, as shown in the previous section.

By adopting the `pluginManagement` block and declaring the `views-json` plugin in the `settings.gradle` file, you ensure consistent usage of the plugin across all projects in the Grails 6 ecosystem. This approach simplifies plugin version control and improves the overall development experience when working with JSON responses in your Grails applications.


##### 6.3 Grails Adoption of "buildSrc" Folder for Buildscript Dependencies

In previous versions of Grails (before Grails 6), managing buildscript dependencies, such as the `views-gradle` plugin, was typically done directly in the main `build.gradle` file. This enables Gradle compilation of JSON views for production environment. Developers would define the repositories and dependencies needed for the buildscript within the `buildscript` block:

.build.gradle
```groovy

buildscript {
repositories {
mavenCentral()
}
dependencies {
// Example: views-gradle plugin
classpath "org.grails.plugins:views-gradle:3.0.0"
}
}

// Apply the views-json plugin
apply plugin: 'views-json'

// Other configurations and dependencies
```

This approach meant that the buildscript dependencies were mixed with the rest of the project's configurations, making the `build.gradle` file longer and potentially harder to maintain. As a result, the buildscript section might become cluttered with various plugin dependencies and other build logic.

With the introduction of Grails 6, there is a significant improvement in managing buildscript dependencies through the use of the `buildSrc` folder. This dedicated folder provides a more organized approach to handle buildscript dependencies, custom Gradle plugins, and extensions specific to the project.

**Benefits of Grails 6 Adoption of "buildSrc" Folder**

1. **Modular Build Configuration:** The `buildSrc` folder acts as a separate mini-project within your Grails application, allowing you to encapsulate build logic, plugins, and dependencies. This separation of concerns improves the organization and modularity of the build configuration.

2. **Streamlined Buildscript Management:** By moving buildscript dependencies to `buildSrc`, you can keep the main `build.gradle` file clean and focused on the application's specific requirements. This reduces clutter and promotes a more concise and clear build script.

3. **Better Collaboration:** The `buildSrc` approach simplifies collaboration within development teams. Build logic can be centralized and shared across projects, enabling a consistent and efficient development workflow.

**Update from Grails 5**

The new Grails 6 application uses `buildSrc/build.gradle`. The buildSrc directory can host a build script if additional configuration is needed (e.g. to apply plugins or to declare dependencies). The `buildSrc` folder in a Grails project follows a specific tree layout, which includes the `build.gradle` file. Here's how the tree layout looks like:

```bash
buildSrc/
├── build.gradle
└── src/
└── main/
└── groovy/
```

**Let's walk through how to manage the `views-gradle` plugin using the `buildSrc` folder in Grails 6:**

**Step 1: Create buildSrc Folder:**

In the root directory of your Grails 6 project, create a new folder named `buildSrc`.

**Step 2: Add buildSrc Script:**

Inside the `buildSrc` folder, create a build.gradle file and specify the `views-gradle` plugin dependency:

.buildSrc/build.gradle
```groovy
repositories {
mavenCentral()
}

dependencies {
implementation "org.grails.plugins:views-gradle:3.0.0"
}
```

**Step 3: Remove apply plugin Statement:**

In the main `build.gradle` file, remove the `buildscript` block and the `apply plugin` statement related to `views-gradle`, as it is now managed in the `buildSrc` folder:

.build.gradle
```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.grails.plugins:views-gradle:3.0.0"
}
}

// No need to apply views-json plugin here
// Remove the apply plugin statement for views-json if it was previously present
apply plugin: 'views-json'

// ... Other configurations and dependencies
```

By using the `buildSrc` folder, developers can separate buildscript dependencies and custom plugin configurations from the main `build.gradle` file. This leads to a cleaner and more concise build script, which is easier to maintain and understand. Additionally, the `buildSrc` approach encourages modularity, as build logic and custom plugins can be centralized and shared across projects, fostering better collaboration and consistency within development teams.

#### 7. GORM for MongoDB Sync Driver:

The GORM for MongoDB is updated to support the latest mongodb-driver-sync. If you are using GORM for MongoDB and making use of specific MongoDB Driver or low-level Mongo API features, consider checking the https://mongodb.github.io/mongo-java-driver/4.0/upgrading/[Upgrading to the 4.0 Driver guide].
Expand Down
4 changes: 2 additions & 2 deletions src/en/ref/Command Line/schema-export.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ The `schema-export` command uses Hibernate's SchemaExport tool to generate Data
== Examples

[source,groovy,subs="attributes+"]
.buildSrc/build.gradle
build.gradle
----
repositories {
mavenCentral()
maven { url = "https://repo.grails.org/grails/core/" }
}
dependencies {
implementation("org.grails.plugins:hibernate5:{gormVersion}")
classpath "org.grails.plugins:hibernate5:{gormVersion}"
}
----

Expand Down
Loading