@@ -14,6 +14,7 @@ import (
1414 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"
1515 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
1616 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
17+ artutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/utils"
1718 "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1819 "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1920 "github.com/jfrog/jfrog-cli-security/utils/techutils"
@@ -558,8 +559,13 @@ func MvnCmd(c *cli.Context) (err error) {
558559 return err
559560 }
560561
561- // FlexPack bypasses all config file requirements
562- if os .Getenv ("JFROG_RUN_NATIVE" ) == "true" {
562+ configFilePath , configExists , err := project .GetProjectConfFilePath (project .Maven )
563+ if err != nil {
564+ return err
565+ }
566+
567+ // FlexPack bypasses all config file requirements (only when no config exists)
568+ if artutils .ShouldRunNative (configFilePath ) && ! configExists {
563569 log .Debug ("Routing to Maven native implementation" )
564570 // Extract build configuration for FlexPack
565571 args := cliutils .ExtractCommand (c )
@@ -572,9 +578,11 @@ func MvnCmd(c *cli.Context) (err error) {
572578 return commands .Exec (mvnCmd )
573579 }
574580
575- configFilePath , err := getProjectConfigPathOrThrow (project .Maven , "mvn" , "mvn-config" )
576- if err != nil {
577- return err
581+ // If config file is missing and not in native mode, return the standard missing-config error.
582+ if ! configExists {
583+ if configFilePath , err = getProjectConfigPathOrThrow (project .Maven , "mvn" , "mvn-config" ); err != nil {
584+ return err
585+ }
578586 }
579587
580588 if c .NArg () < 1 {
@@ -629,11 +637,35 @@ func GradleCmd(c *cli.Context) (err error) {
629637 return err
630638 }
631639
632- nativeMode := os .Getenv ("JFROG_RUN_NATIVE" ) == "true"
640+ resolveServer := func (args []string ) ([]string , * coreConfig.ServerDetails , error ) {
641+ cleanedArgs , serverID , err := coreutils .ExtractServerIdFromCommand (args )
642+ if err != nil {
643+ return nil , nil , fmt .Errorf ("failed to extract server ID: %w" , err )
644+ }
645+
646+ if serverID == "" {
647+ serverDetails , err := coreConfig .GetDefaultServerConf ()
648+ if err != nil {
649+ return cleanedArgs , nil , err
650+ }
651+ if serverDetails == nil {
652+ return cleanedArgs , nil , fmt .Errorf ("no default server configuration found. Please configure a server using 'jfrog config add' or specify a server using --server-id" )
653+ }
654+ return cleanedArgs , serverDetails , nil
655+ }
656+
657+ serverDetails , err := coreConfig .GetSpecificConfig (serverID , true , true )
658+ if err != nil {
659+ return nil , nil , fmt .Errorf ("failed to get server configuration for ID '%s': %w" , serverID , err )
660+ }
661+ return cleanedArgs , serverDetails , nil
662+ }
663+
633664 configFilePath , configExists , err := project .GetProjectConfFilePath (project .Gradle )
634665 if err != nil {
635666 return err
636667 }
668+ nativeMode := artutils .ShouldRunNative (configFilePath )
637669
638670 // FlexPack native mode for Gradle (bypasses config file requirements)
639671 if nativeMode && ! configExists {
@@ -642,13 +674,17 @@ func GradleCmd(c *cli.Context) (err error) {
642674 return cliutils .WrongNumberOfArgumentsHandler (c )
643675 }
644676 args := cliutils .ExtractCommand (c )
677+ args , serverDetails , err := resolveServer (args )
678+ if err != nil {
679+ return err
680+ }
645681 filteredGradleArgs , buildConfiguration , err := build .ExtractBuildDetailsFromArgs (args )
646682 if err != nil {
647683 return err
648684 }
649685
650686 // Create Gradle command with FlexPack (no config file needed)
651- gradleCmd := gradle .NewGradleCommand ().SetConfiguration (buildConfiguration ).SetTasks (filteredGradleArgs ).SetConfigPath ("" )
687+ gradleCmd := gradle .NewGradleCommand ().SetConfiguration (buildConfiguration ).SetTasks (filteredGradleArgs ).SetConfigPath ("" ). SetServerDetails ( serverDetails )
652688 return commands .Exec (gradleCmd )
653689 }
654690
@@ -664,6 +700,10 @@ func GradleCmd(c *cli.Context) (err error) {
664700 return cliutils .WrongNumberOfArgumentsHandler (c )
665701 }
666702 args := cliutils .ExtractCommand (c )
703+ args , serverDetails , err := resolveServer (args )
704+ if err != nil {
705+ return err
706+ }
667707 filteredGradleArgs , buildConfiguration , err := build .ExtractBuildDetailsFromArgs (args )
668708 if err != nil {
669709 return err
@@ -695,7 +735,7 @@ func GradleCmd(c *cli.Context) (err error) {
695735 return err
696736 }
697737 printDeploymentView := log .IsStdErrTerminal ()
698- gradleCmd := gradle .NewGradleCommand ().SetConfiguration (buildConfiguration ).SetTasks (filteredGradleArgs ).SetConfigPath (configFilePath ).SetThreads (threads ).SetDetailedSummary (detailedSummary || printDeploymentView ).SetXrayScan (xrayScan ).SetScanOutputFormat (scanOutputFormat )
738+ gradleCmd := gradle .NewGradleCommand ().SetConfiguration (buildConfiguration ).SetTasks (filteredGradleArgs ).SetConfigPath (configFilePath ).SetThreads (threads ).SetDetailedSummary (detailedSummary || printDeploymentView ).SetXrayScan (xrayScan ).SetScanOutputFormat (scanOutputFormat ). SetServerDetails ( serverDetails )
699739 err = commands .Exec (gradleCmd )
700740 result := gradleCmd .Result ()
701741 defer cliutils .CleanupResult (result , & err )
@@ -1533,7 +1573,7 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
15331573 }
15341574
15351575 // FlexPack native mode for Poetry (bypasses config file requirements)
1536- if os . Getenv ( "JFROG_RUN_NATIVE" ) == "true" && projectType == project .Poetry {
1576+ if artutils . ShouldRunNative ( "" ) && projectType == project .Poetry {
15371577 log .Debug ("Routing to Poetry native implementation" )
15381578 args := cliutils .ExtractCommand (c )
15391579 filteredArgs , buildConfiguration , err := build .ExtractBuildDetailsFromArgs (args )
0 commit comments