Re: Grab and boms

Per Nyfelt <[email protected]> Tue, 22 Apr 2025 20:45:59 +0200
Newsgroups gmane.comp.lang.groovy.user
Organization Alipsa HB
Message-ID <[email protected]>
I removed the .m2 and Grape cache and tried this:

#!/usr/bin/env groovy @Grab(group='se.alipsa.matrix', module='matrix-bom', version='2.1.0', type='pom')
@Grab('se.alipsa.matrix:matrix-core')

def userHome = System.getProperty("user.home")
File cacheDir =new File(userHome,".groovy/grapes/se.alipsa.matrix/matrix-core/jars")
boolean coreJarExists =false println"Grape cache: ${cacheDir.absolutePath}jars:" cacheDir.listFiles().eachWithIndex{ it, idx-> println idx +". " + it.name if (it.name.contains("matrix-core-3.1.0.jar")) {
     coreJarExists =true }
} println"\nmatrix-core-3.1.0.jar was ${coreJarExists ?'found' :'NOT found'}in ${cacheDir.absolutePath}"

And get the following output:
Grape cache: /home/per/.groovy/grapes/se.alipsa.matrix/matrix-core/jars 
jars:
0. matrix-core-3.2.0.jar

matrix-core-3.1.0.jar was NOT found in 
/home/per/.groovy/grapes/se.alipsa.matrix/matrix-core/jars

So it confirms that not specifying a version causes Grab to fetch 
whatever latest version it can find in maven central ignoring the bom.

On 4/22/25 20:23, Per Nyfelt wrote:
>
> Hi, is it possible to use boms in @Grab?
>
> I tried the following in a groovy script:
>
> #!/usr/bin/env groovy @Grab(group='se.alipsa.matrix', module='matrix-bom', version='2.2.0', type='pom')
> @Grab('se.alipsa.matrix:matrix-core')
>
> import se.alipsa.matrix.core.*
> import java.util.time.*
>
> import java.time.LocalDate
>
> Matrix empData =Matrix.builder()
>      .columns(
>          emp_id:1..5,
>          emp_name: ["Rick","Dan","Michelle","Ryan","Gary"],
>          salary: [623.3,515.2,611.0,729.0,843.25],
>          start_date:ListConverter.toLocalDates("2013-01-01","2012-03-27","2013-09-23","2014-11-15","2014-05-11"))
>      .types([int, String, Number, LocalDate])
>      .build()
> println empData.content()
>
> While it does fetch the bom file and everything "works", it does not 
> honor the versions specified in it and instead for the subsequent grab 
> (matrix-core), but just fetches the latest one from the .m2 cache
>
> Is there a way to enforce the versions specified in the bom?
>
> Regards,
>
> Per
>