@@ -32,6 +32,17 @@ function stripString(depPart) {
3232 return depPart . replaceAll ( / [ " ' ] / g, "" )
3333}
3434
35+ /** this function checks whether a line from `gradle dependencies` output contains a version or not
36+ *
37+ * @param line the line from `gradle dependencies` output.
38+ * @return {*|boolean }
39+ */
40+ function containsVersion ( line ) {
41+ let lineStriped = line . replace ( "(n)" , "" ) . trim ( )
42+ return ( lineStriped . match ( / \W * [ a - z 0 - 9 . - ] + : [ a - z 0 - 9 . - ] + : [ 0 - 9 ] + [ . ] [ 0 - 9 ] + ( .[ 0 - 9 ] + ) ? ( .* ) ? .* / )
43+ || lineStriped . match ( / .* v e r s i o n : \s ? ( ' ) ? [ 0 - 9 ] + [ . ] [ 0 - 9 ] + ( .[ 0 - 9 ] + ) ? ( ' ) ? / ) ) && ! lineStriped . includes ( "libs." )
44+ }
45+
3546export default class Java_gradle extends Base_java {
3647
3748 /**
@@ -210,10 +221,14 @@ export default class Java_gradle extends Base_java {
210221 // transform gradle dependency tree to the form of maven dependency tree to use common sbom build algorithm in Base_java parent */
211222 let arrayForSbom = lines . map ( dependency => dependency . replaceAll ( "---" , "-" ) . replaceAll ( " " , " " ) )
212223 . map ( dependency => dependency . replaceAll ( / : ( .* ) : ( .* ) - > ( .* ) $ / g, ":$1:$3" ) )
224+ . map ( dependency => dependency . replaceAll ( / : ( .* ) \W * - > \W * ( .* ) $ / g, ":$1:$2" ) )
213225 . map ( dependency => dependency . replaceAll ( / ( .* ) : ( .* ) : ( .* ) $ / g, "$1:$2:jar:$3" ) )
214226 . map ( dependency => dependency . replaceAll ( / ( n ) $ / g) , "" )
215227 . map ( dependency => `${ dependency } :compile` ) ;
216- this . parseDependencyTree ( root , 0 , arrayForSbom . slice ( 1 ) , sbom )
228+ if ( ! containsVersion ( arrayForSbom [ 0 ] ) ) {
229+ arrayForSbom = arrayForSbom . slice ( 1 )
230+ }
231+ this . parseDependencyTree ( root + ":compile" , 0 , arrayForSbom , sbom )
217232 let ignoredDeps = this . #getIgnoredDeps( manifestPath )
218233 return sbom . filterIgnoredDepsIncludingVersion ( ignoredDeps ) . getAsJsonString ( ) ;
219234 }
@@ -236,7 +251,9 @@ export default class Java_gradle extends Base_java {
236251 }
237252
238253 if ( startFound && dependency . trim ( ) !== "" ) {
239- resultList . push ( dependenciesList [ dependency ] )
254+ if ( startMarker === 'runtimeClasspath' || containsVersion ( dependenciesList [ dependency ] ) ) {
255+ resultList . push ( dependenciesList [ dependency ] )
256+ }
240257 }
241258
242259 if ( startFound && dependenciesList [ dependency ] . trim ( ) === "" ) {
0 commit comments