Instructions for installing the plugin from maven in settings.gradle results in error message about not being part of the build in Gradle 7.0.2
jamesmortensen opened this issue · comments
I was trying to upgrade from Gradle 4.10.3 to Gradle 7.0.2. I can run gradle appengineRun -b service1-7.0.2.build.gradle -c new-7.0.2.settings.gradle --info
with Gradle 4.10.3, but with Gradle 7.0.2, I get the following error message:
Build file '/Users/jem/project/service1-7.0.2.build.gradle' is not part of the build defined by settings file '/Users/jem/project/new-7.0.2.settings.gradle'. If this is an unrelated build, it must have its own settings file.
The instructions in is repository README say that the app-gradle-plugin is not available in the Gradle repository and must be loaded from the Maven repository. As instructed, I put the following in the new-7.0.2.settings.gradle file:
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
// add mavenLocal() if you are using a locally built version of the plugin
}
resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith('com.google.cloud.tools.appengine')) {
useModule("com.google.cloud.tools:appengine-gradle-plugin:2.4.1")
}
}
}
}
I then configure the service1-7.0.2.build.gradle as follows:
plugins {
id 'java'
id 'war'
id 'com.google.cloud.tools.appengine-appenginewebxml'
id "org.rm3l.datanucleus-gradle-plugin" version "1.7.0"
}
/**
* treat Maven as a repository, as well as the war/WEB-INF/lib folder to include
* dependencies that are in version control already
*/
repositories {
mavenCentral()
jcenter {
url "http://jcenter.bintray.com/"
url "https://plugins.gradle.org/m2/"
}
flatDir {
dirs 'war/WEB-INF/lib'
}
}
war {
from 'jsp' // adds a file-set to the root of the archive
webAppDirName = 'war'
webXml = file('war/WEB-INF/deployment-descriptors/web-default-local8080.xml') // copies a file to WEB-INF/web.xml
}
dependencies {
compile fileTree(dir: 'war/WEB-INF/lib', include: ['*.jar'])
}
// https://docs.gradle.org/4.10.3/userguide/building_java_projects.html#sec:compile
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['resources']
}
resources {
srcDirs = ['src', 'props']
}
}
test {
java {
srcDirs = ['test']
}
}
}
appengine {
run {
host = "0.0.0.0"
jvmFlags = [
"-Ddatastore.backing_store=~/.gcp_data/project/local_db.bin"
]
}
deploy {
version = "GCLOUD_CONFIG"
projectId = "GCLOUD_CONFIG"
}
}
task datanucleusEnhance {
description "Enhance JPA model classes using DataNucleus Enhancer"
dependsOn compileJava
doLast {
// define the entity classes
def entityFiles = fileTree(sourceSets.main.output.classesDir).matching {
include 'com/project/jdo/*.class'
include 'com/project/jdo/*.class'
include 'com/project/reminder/jdo/*.class'
include 'com/project/cacheutils/*.class'
}
println "Enhancing with DataNucleus the following files"
entityFiles.getFiles().each {
println it
}
// define Ant task for DataNucleus Enhancer
ant.taskdef(
name : 'datanucleusenhancer',
classpath : sourceSets.main.runtimeClasspath.asPath,
// the below is for DataNucleus Enhancer 3.1.1
classname : 'org.datanucleus.enhancer.tools.EnhancerTask'
)
// run the DataNucleus Enhancer as an Ant task
ant.datanucleusenhancer(
classpath: sourceSets.main.runtimeClasspath.asPath,
verbose: true,
api: "JDO") {
entityFiles.addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
}
}
}
classes.dependsOn(datanucleusEnhance)
I run with the following command, so that we use the correct build.gradle and settings.gradle for Gradle 7.0.2, as well as ensuring gradle uses Java 8:
$ gradle appengineRun -b service1-7.0.2.build.gradle -c new-7.0.2.settings.gradle --info -Dorg.gradle.java.home=/Users/jem/.jenv/versions/1.8.0.162
I don't understand the error message, suggesting my settings is defining another build. I don't have anything in the settings file other than the code to load the app-gradle plugin from Maven. If someone can shed some light on this, that would be awesome! Thank you!
UPDATE: I discovered that if I renamed the new-7.0.2.settings.gradle to settings.gradle and used it as the default instead of passing in the non-default settings using the -c argument, I got past that error message. However, this seems like a bug in gradle itself as gradle -h
shows the following option:
-c, --settings-file Specify the settings file.
I guess this should be closed and instead reopened in Gradle's repo as a bug.
@jamesmortensen Yes, if this is a behavior change in Gradle, please open an issue with the project.
I remember a similar issue. The error message may not be obvious, but I can understand what it's complaining about. Probably you shouldn't use both -b
and -c
. Instead, set the custom build file name in the settings file, e.g.,
rootProject.buildFileName = "service1-7.0.2.build.gradle"