This task has been canceled!

6

Created by
johndon 216 about 3 years ago

Java/Gradle how to include version number for gradle build that's accessible from beans

I want to specify a version of my software in the gradle e.g. like this:


project(':my-application') {
	apply plugin: 'org.springframework.boot'

	version = '1.x.x'

	dependencies {
        ...
	}
}

Now when making a gradle build this 1.x.x version should be part of the jar. Also I want to be able to access this version from within my beans:

@Component
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		logger.info("Starting my application");

        // prints version 1.1.x
        logger.info("Version of my app is: {}", version);
    }
}

See task infos

Solutions (1)

0

2

mBCH

robert 1k about 3 years ago
20 mBCH
Accepted solution
robert 1k about 3 years ago

There is a typo. In it.replace('%projectVersion%', .version) you need to remove the dot before version

0

johndon 216 about 3 years ago
Creator

great this worked! thanks!

0