Skip to content

Conversation

arberg
Copy link
Contributor

@arberg arberg commented Nov 17, 2020

Thank you for the almost awesome script, and certainly extremely helpful script. I have made it better, adding still more conversions, including map conversions, which turned out to be a bit to crazy to get right, but its nice :). I still miss parenthesis matching, but felt it wasn't worth it. The myBlock -> named("myBlock") messed up some source-code I had, but it was easy enough to revert, so not really worth modifying the script for that. Well I would have done it if I knew how to match parentesis in java without coding it myself...

Once again, thanks for the script.

Alex Rune Berg and others added 3 commits November 16, 2020 17:10
…aining a 'val' (for old groovy 'def foo=42')

convertArrayExpression: Prevent mapping array lookups (if lookup by integer literal)
Added convertMapExpression for handling maps
Added convertAndroidBuildConfigFunctions for more functions() conversions like buildConfigField()
Added convertProductFlavors: Added 'productFlavor { create("name") {' conversion (like others)
Added more equals conversions, eg databinding
@bernaferrari
Copy link
Owner

bernaferrari commented Nov 17, 2020

Really awesome!! Thanks a lot!
Just two questions:

Shouldn't Windows people use winget instead of other things? I'm not sure kotlin is available there, but everybody should have access to it.

Second, do you mind updating our test file? It is currently failing, since the output changed. There is a file with the expected output, and github performs the diff on every commit.

@arberg
Copy link
Contributor Author

arberg commented Nov 20, 2020

Ah, tests are a thing. Sounds wise.

I've added a few more details to the conversion.

I've updated the test so some of the new stuff is tested, and updated the expected result, as you can see.

Your expected actually contained a bad block with garbled code, due to the bug which duplicated arbitrary sections. That's what happens on quick and dirty copy my output as expected test-result. But its also pretty understandable how that can happen, it kind of did look right on first glance, and any test is still its far better than no test. I tried comparing the input with the output with beyond compare, and it looks reasonable now.

I also tried adding some links in the output, though it kind of sucks to have it there, but it can really help with some good guides, and I stumbled across one such

@bernaferrari
Copy link
Owner

That's great, thanks!

@bernaferrari bernaferrari merged commit ae9afcf into bernaferrari:master Nov 20, 2020
@arberg
Copy link
Contributor Author

arberg commented Nov 21, 2020

Ah, about windows, the winget is still in insider mode, and didn't work for me, maybe because I already had it installed in non-insider variant. Anayway scoop is fine for now for windows users.

mherod pushed a commit to mherod/GradleKotlinConverter that referenced this pull request Dec 13, 2020
* Allow non-number fields, but warn user and link to info on buildSrc. Convert java primitives to kotlin types.

* convertVariableDeclaration: fixed wrong replacement when already containing a 'val' (for old groovy 'def foo=42')
convertArrayExpression: Prevent mapping array lookups (if lookup by integer literal)
Added convertMapExpression for handling maps
Added convertAndroidBuildConfigFunctions for more functions() conversions like buildConfigField()
Added convertProductFlavors: Added 'productFlavor { create("name") {' conversion (like others)
Added more equals conversions, eg databinding

* readme for windows

* Use new com.android.tools.build:gradle:4.1.0 syntax for manifestPlaceholders

* Updated expected build test

* A few more conversions and added tests and updated expected test result

* gitignore

Co-authored-by: Alex Rune Berg <arberg.bnr@gmail.com>
@bernaferrari
Copy link
Owner

You once helped me. I refactored the project into this website: https://gradle-kotlin-converter.vercel.app/

@arberg
Copy link
Contributor Author

arberg commented Sep 25, 2024

Thank you Bernardo, looks cool.

I tried it on a java-library gradle file. It's still pretty neat for converting the simple stuff, and cool to have it simply in a url for get it up and running quickly, and interactive as well.

Here are some few lines where it could be improved if you so desire. Though be warned, it could be a huge rabit hole to try to get it all, not that I'm up for that right now.

This is the input:

plugins {
    id 'java-library'
}
apply from: '../versions.gradle'
apply from: '../config.gradle'
group 'dk.bnr'
version project.file('VERSION-bnr-common').text.trim()

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

println "Target: $target"

Which should have given this output if it was to be 'perfect' :

plugins {
    id("java-library")
}
apply(from = "../versions.gradle")
apply(from = "../config.gradle")
group = "dk.bnr"
version = project.file("VERSION-bnr-common").readText().trim()

java {
    sourceCompatibility = JavaVersion.VERSION_11  // Set to the desired Java version
    targetCompatibility = JavaVersion.VERSION_11  // Set to the desired Java version
}

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

Successfully merging this pull request may close these issues.

2 participants