Skip to content

Commit 2677800

Browse files
committed
Don't provide database driver dependency when using mongodb feature
Closes gh-1001 See gh-939
1 parent 4f23f7b commit 2677800

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

grace-shell/src/main/groovy/org/grails/cli/profile/commands/CreateAppCommand.groovy

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import org.grails.build.logging.GrailsConsoleAntProject
5353
import org.grails.build.logging.GrailsConsoleLogger
5454
import org.grails.build.parsing.CommandLine
5555
import org.grails.cli.GrailsCli
56-
import org.grails.cli.profile.CommandArgument
5756
import org.grails.cli.profile.CommandDescription
5857
import org.grails.cli.profile.ExecutionContext
5958
import org.grails.cli.profile.Feature
@@ -270,7 +269,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
270269
springBootVersion: specificBootVersion,
271270
features: features,
272271
skippedFeatures: skippedFeatures,
273-
database: commandLine.optionValue(DATABASE_FLAG) ?: (commandLine.optionValue('d') ?: 'h2'),
272+
database: commandLine.optionValue(DATABASE_FLAG) ?: commandLine.optionValue('d'),
274273
template: commandLine.optionValue('template') ?: commandLine.optionValue('m'),
275274
inplace: inPlace,
276275
minimal: commandLine.hasOption(MINIMAL_FLAG),
@@ -377,27 +376,39 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
377376
}
378377

379378
List<Feature> features = cmd.minimal ? [] : evaluateFeatures(profileInstance, cmd.features, cmd.skippedFeatures, cmd.console)
379+
List<String> featureNames = features*.name
380380

381381
Map<String, String> variables = initializeVariables(appName, groupName, defaultPackageName, profileName, features, cmd.template, cmd.grailsVersion)
382382
Map<String, String> args = new HashMap<>()
383383
args.putAll(cmd.args)
384-
args.put(FEATURES_FLAG, features*.name?.join(','))
384+
args.put(FEATURES_FLAG, featureNames?.join(','))
385385

386386
Project project = createAntProject(cmd.appName, projectTargetDirectory, variables, args, console, cmd.verbose, cmd.quiet)
387387
GrailsConsoleAntBuilder ant = new GrailsConsoleAntBuilder(project)
388388

389389
String projectType = getName().substring(7)
390390

391+
String databaseType
392+
if (!cmd.database && featureNames?.contains('hibernate')) {
393+
databaseType = 'h2'
394+
}
395+
else if (!cmd.database && featureNames?.contains('mongodb')) {
396+
databaseType = 'MongoDB'
397+
}
398+
else {
399+
databaseType = cmd.database
400+
}
401+
391402
console.addStatus("Creating a new ${projectType == 'app' ? 'application' : projectType}")
392403
console.println()
393404
console.println(" Name:".padRight(20) + appName)
394405
if (projectType == 'app' || projectType == 'plugin') {
395406
console.println(" Package:".padRight(20) + defaultPackageName)
396407
}
397408
console.println(" Profile:".padRight(20) + profileName)
398-
console.println(" Features:".padRight(20) + features*.name?.join(', '))
399-
if (projectType == 'app') {
400-
console.println(" Database:".padRight(20) + cmd.database)
409+
console.println(" Features:".padRight(20) + featureNames?.join(', '))
410+
if ((projectType == 'app' || projectType == 'plugin') && databaseType) {
411+
console.println(" Database:".padRight(20) + databaseType)
401412
}
402413
if (cmd.template) {
403414
console.println(" Template:".padRight(20) + cmd.template)
@@ -1039,7 +1050,10 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
10391050
buildDependencies.addAll f.dependencies.findAll { Dependency dep -> dep.scope == 'build' }
10401051
}
10411052

1042-
dependencies.add(new Dependency(Databases.getDriverArtifact(args['database']), 'runtime'))
1053+
List<String> featureNames = features*.name
1054+
if (featureNames?.contains('hibernate')) {
1055+
dependencies.add(new Dependency(Databases.getDriverArtifact(args['database']), 'runtime'))
1056+
}
10431057

10441058
dependencies.add(new Dependency(this.profileRepository.getProfileArtifact(profileName), 'profile'))
10451059

0 commit comments

Comments
 (0)