Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyphens in Maven variable names get pasted with spaces surrounding them in the Gradle dependency #4

Closed
platan opened this issue Dec 27, 2017 · 2 comments
Assignees

Comments

@platan
Copy link
Owner

platan commented Dec 27, 2017

Reported by @banana-ben in #3 (comment):

hyphens in Maven variable names get pasted with spaces surrounding them in the Gradle dependency, ie:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
	<version>${spring-boot-version}</version>
</dependency>

becomes
compile "org.springframework.boot:spring-boot-starter-jdbc:${spring - boot - version}"

@platan platan self-assigned this Dec 27, 2017
@platan
Copy link
Owner Author

platan commented Dec 28, 2017

Hyphen represents an arithmetic operator in Groovy. So you can't use ${spring-boot-version} to read value of property with a key spring-boot-version. But you can read the value using property() method:
compile "org.springframework.boot:spring-boot-starter-jdbc:${property('spring-boot-version')}"
Here https://discuss.gradle.org/t/trying-to-define-global-ext-properties-version-for-dependencies/11159/2 you can find more info about variables with 'dot' in name (similar case to hyphen in name) and ways to define them. But probably the simplest solution is to use variable names without hyphens (with _ instead of - (3,221 code results at GitHub) or using camel case(47,415 code results at Gitub)).

These extra spaces added around hyphens is not a bug in 'Gradle dependencies formatter' plugin. It's a feature of IntelliJ Groovy plugin ;-) If you paste

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
	<version>${spring-boot-version}</version>
</dependency>

into double quoted string in groovy file you will get:

"<dependency>\n" +
"\t<groupId>org.springframework.boot</groupId>\n" +
"\t<artifactId>spring-boot-starter-jdbc</artifactId>\n" +
"\t<version>${spring - boot - version}</version>\n" +
"</dependency>"

You can disable this feature in Settings > Editor > Code Style > Groovy > Spaces > Around Operators > additive Operators (+, -)

@mxwlsavard
Copy link

Oh good catch. I didn't notice this because I was just removing those variables in the gradle file, my bad! And thanks again for looking into these issues, this plugin is super helpful!

@platan platan closed this as completed Dec 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants