Open colindean opened 8 years ago
Strange. You usage is more or less exactly how we use semver-git internally. You could try to apply semver-git with:
allprojects {
ext.nextVersion = 'patch'
ext.snapshotSuffix = "-dev-<count>-g<sha>"
apply plugin: "com.cinnober.gradle.semver-git"
}
since that is how it is generally applied here, though it seems to me that your build file should work.
Unfortunately, that still doesn't work. I'm going to try a barebones project and see what I can make happen. It's entirely possible that something else in our build.gradle
is acting up.
I'm able to reproduce it with the barebones config.
mkdir gradlewtf && cd gradlewtf
atom build.gradle
Put this in build.gradle
:
plugins {
id 'scala'
id "com.cinnober.gradle.semver-git" version "2.2.2" // semantic versioning from git
}
apply plugin: 'scala'
ext {
nextVersion = "patch"
snapshotSuffix = "-dev-<count>-g<sha>"
}
apply plugin: "com.cinnober.gradle.semver-git"
Some exploration to try:
gw showVersion # behavior undefined, since we're not yet in a git repo
gw --version
git init .
git add build.gradle
git commit -m "Initial commit"
git tag -a 1.0.0 -m "Initial"
git describe
gw showVersion # 1.0.0 expected
echo ".gradle" >> .gitignore
git add .gitignore
git commit -av -m "Adds gitignore"
gw showVersion # 1.0.1-dev-1-gd34db33f or other hash expected
My output:
[13:22:25 cdean@lusankya /tmp ]
$ mkdir gradlewtf && cd gradlewtf
[13:22:26 cdean@lusankya /tmp/gradlewtf ]
$ atom build.gradle
[13:22:28 cdean@lusankya /tmp/gradlewtf ]
$ gw showVersion
No gradlew set up for this project; consider setting one up:
http://gradle.org/docs/current/userguide/gradle_wrapper.html
Using gradle at '/usr/local/bin/gradle' to run buildfile '/tmp/gradlewtf/build.gradle':
:showVersion
Version: 0.1.0-SNAPSHOT
BUILD SUCCESSFUL
Total time: 0.599 secs
[13:22:46 cdean@lusankya /tmp/gradlewtf ]
$ gw --version
No gradlew set up for this project; consider setting one up:
http://gradle.org/docs/current/userguide/gradle_wrapper.html
Using gradle at '/usr/local/bin/gradle' to run buildfile '/tmp/gradlewtf/build.gradle':
------------------------------------------------------------
Gradle 2.11
------------------------------------------------------------
Build time: 2016-02-08 07:59:16 UTC
Build number: none
Revision: 584db1c7c90bdd1de1d1c4c51271c665bfcba978
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_66 (Oracle Corporation 25.66-b17)
OS: Mac OS X 10.10.5 x86_64
[13:22:55 cdean@lusankya /tmp/gradlewtf ]
$ git init .
Initialized empty Git repository in /private/tmp/gradlewtf/.git/
[13:23:03 cdean@lusankya /tmp/gradlewtf ]
± (master #%) $ git add build.gradle
[13:23:04 cdean@lusankya /tmp/gradlewtf ]
± (master +) $ git commit -m "Initial commit"
[master (root-commit) 584d2b1] Initial commit
1 file changed, 10 insertions(+)
create mode 100644 build.gradle
[13:23:04 cdean@lusankya /tmp/gradlewtf ]
± (master) $ git tag -a 1.0.0 -m "Initial"
[13:23:05 cdean@lusankya /tmp/gradlewtf ]
± (master) $ git describe
1.0.0
[13:23:13 cdean@lusankya /tmp/gradlewtf ]
± (master) $ gw showVersion
No gradlew set up for this project; consider setting one up:
http://gradle.org/docs/current/userguide/gradle_wrapper.html
Using gradle at '/usr/local/bin/gradle' to run buildfile '/tmp/gradlewtf/build.gradle':
:showVersion
Version: 1.0.0
BUILD SUCCESSFUL
Total time: 0.649 secs
[13:23:26 cdean@lusankya /tmp/gradlewtf ]
± (master) $ echo ".gradle" >> .gitignore
[13:23:33 cdean@lusankya /tmp/gradlewtf ]
± (master %) $ git add .gitignore
[13:23:33 cdean@lusankya /tmp/gradlewtf ]
± (master +) $ git commit -av -m "Adds gitignore"
[master 41da2c7] Adds gitignore
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
[13:23:34 cdean@lusankya /tmp/gradlewtf ]
± (master) $ git describe
1.0.0-1-g41da2c7
[13:23:38 cdean@lusankya /tmp/gradlewtf ]
± (master) $ gw showVersion
No gradlew set up for this project; consider setting one up:
http://gradle.org/docs/current/userguide/gradle_wrapper.html
Using gradle at '/usr/local/bin/gradle' to run buildfile '/tmp/gradlewtf/build.gradle':
:showVersion
Version: 1.1.0-SNAPSHOT
BUILD SUCCESSFUL
Total time: 0.562 secs
[13:23:45 cdean@lusankya /tmp/gradlewtf ]
± (master) $
As you can see, at the end, it's defaulting to bumping minor and -SNAPSHOT
.
I've also tried switching to the java
plugin in case the scala
plugin does something weird. No difference.
Hi Colin,
The project.version is assigned by semver-git when the plugin is applied. This means that the related properties must to be set before that step.
/Mikael
I reversed the order so that the application of semver-git
happens before anything else:
plugins {
id 'java'
id "com.cinnober.gradle.semver-git" version "2.2.2" // semantic versioning from git
}
ext {
nextVersion = "patch"
snapshotSuffix = "-dev-<count>-g<sha>"
}
apply plugin: "com.cinnober.gradle.semver-git"
apply plugin: 'java'
My configuration is still having no effect.
Thrashing a bit, I tried adding a buildscript
block, but apparently that's not a valid approach since buildscript
cannot contain a plugins
block.
I'm not sure what else I can change. @mbrannstrom @mojocinn, what version of Gradle are you using?
OK, some progress:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.cinnober.gradle:semver-git:2.2.2"
}
}
plugins {
id 'java'
// id "com.cinnober.gradle.semver-git" version "2.2.2" // semantic versioning from git
}
ext.nextVersion = "patch"
ext.snapshotSuffix = "-dev-<count>-g<sha>"
apply plugin: "com.cinnober.gradle.semver-git"
apply plugin: 'java'
This works, and so does this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'com.cinnober.gradle', name: 'semver-git', version: '2.2.0'
}
}
plugins {
id 'java'
// id "com.cinnober.gradle.semver-git" version "2.2.2" // semantic versioning from git
}
ext.nextVersion = "patch"
ext.snapshotSuffix = "-dev-<count>-g<sha>"
apply plugin: "com.cinnober.gradle.semver-git"
apply plugin: 'java'
[15:10:56 cdean@lusankya /tmp/gradlewtf ]
± (master *) $ gw showVersion
No gradlew set up for this project; consider setting one up:
http://gradle.org/docs/current/userguide/gradle_wrapper.html
Using gradle at '/usr/local/bin/gradle' to run buildfile '/tmp/gradlewtf/build.gradle':
:showVersion
Version: 1.0.1--dev-1-g41da2c7
BUILD SUCCESSFUL
Total time: 0.683 secs
I can't remember exactly, but I think I found semver-git
through the Gradle plugins page for semver-git and used the newer syntax. It works when I use the older syntax provided there, or the syntax (with an error fixed, submitting that momentarily) version of what's on this repo's README. I'm thinking that Gradle's newer plugins
infrastructure doesn't load the plugin at the right time.
Probably the take-away from this is a modification to the README which states NOT to use the newer plugins
way of including it.
The newer way plugins { id .. }
has other problems as well. For example it does not work inside a submodules
block, not for any gradle plugin.
It is an experimental feature, and I suggest always using the old buildscript { repositories .. }
with apply plugin: ...
syntax, because first it will be on the top level, then someone will move it to e.g. a submodules
block, and then it won't work.
Thanks for the insight.
On Apr 12, 2016, 01:48, at 01:48, "Mikael Brännström" notifications@github.com wrote:
The newer way
plugins { id .. }
has other problems as well. For example it does not work inside asubmodules
block, not for any gradle plugin.It is an experimental feature, and I suggest always using the old
buildscript { repositories .. }
withapply plugin: ...
syntax, because first it will be on the top level, then someone will move it to e.g. asubmodules
block, and then it won't work.
You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/cinnober/semver-git/issues/3#issuecomment-208717989
I just got bit by this again on a new project. Is there any way to detect that it's running, or perhaps output some debug logging to show what it's doing? I probably burned 30 minutes trying to figure out what was incorrectly configured because someone else did it this time.
@colindean if you move the ext {} into your buildscript {} this should work
If you want a simple debug, try
task version doLast {task -> println "This is $task.project.name $task.project.version" }
This is likely user error, as I'm still pretty new to Gradle.
My incredibly pared down
build.gradle
, untested in this context:I have a tag I created with
git tag -a 99.9.9 -m "Test tag for testing"
. I have one commit more on top of it.I expect the output of
./gradlew printVersion
to contain99.9.10-dev-1-gd34db33f
or something similar. It instead prints something like this:I pretty certain that I have
ext
in the right place, but it appears not to be effective. What do I need to change?I'm on Gradle 2.10.