How to set project name / group / version, as well as compatibility {source, target} in one file?

I intend to generalize the use of gradle for my projects and would like to reuse the same build file everywhere. Unfortunately, I am at a loss to define the properties specified in $ subject in one file to facilitate transfer.

This is gradle 1.6.

What I tried failed on any attempts:

  • gradle.properties : it is impossible to change the name (read-only, you need to use settings.gradle and redefine the name of the root project!); {source,target}Compatibility not taken into account;
  • settings.gradle : {source,target}Compatibility not taken into account!

So what is the right method to achieve this? What I have tried so far in gradle.properties :

 group = something name = whatever # cannot do! version = whatever sourceCompatibility = whatever # not taken into account! 

And in settings.gradle :

 sourceCompatibility = "whatever"; # not taken into account! 

EDIT Well, the problem of "name" simply cannot be solved; for the rest, I used a different file, which I use in the assembly file. "Name management" is really wrong: /

EDIT 2 Now it's 2014 and gradle 1.12, and the problem is still not resolved ...

+76
java gradle
Jun 23 '13 at 16:31
source share
5 answers

gradle.properties

 theGroup=some.group theName=someName theVersion=1.0 theSourceCompatibility=1.6 

settings.gradle:

 rootProject.name = theName 

build.gradle:

 apply plugin: "java" group = theGroup version = theVersion sourceCompatibility = theSourceCompatibility 
+111
Jun 23 '13 at 16:52
source share

I found a solution to a similar problem. I am using Gradle 1.11 (in April 2014). The project name can be changed directly in the settings.gradle file as follows:

  rootProject.name='YourNewName' 

This will take care of loading into the repository (Artifactory with its plugin for me) with the correct artifact.

+20
Mar 31 '14 at 1:41
source share

I set the baseName of the artifact so that it does not depend on the name of the assembly project, which allows me to achieve what you want:

 jar { baseName "core" } 

With this set of properties, even if my project name is "foo", when I run gradle install , the artifact is published with the name core instead of foo .

+20
Aug 20 '15 at 12:38
source share

This seems to be possible in settings.gradle with something like this.

 rootProject.name = 'someName' gradle.rootProject { it.sourceCompatibility = '1.7' } 

I recently got advice that a project property can be set using a closure that will be called later when Project is available.

+3
Jun 12 '17 at 12:21
source share

use buildSrc with Gradle Kotlin DSL, see full working example here: GitHub daggerok / spring-fu-jafu-example buildSrc / src / main / java / Globals.kt

0
May 7 '19 at
source share



All Articles