Code review comment: Need to keep jvmTarget option since we have some tool-integration test on running a jar which by default use ballerina-tools distribution. We can do some modifications in integration test utils to run jvm integration tests on jballerina distribution. hence keep this for moment.

Code under review:
public void execute() {
        if (helpFlag) {
            String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(BUILD_COMMAND);
            outStream.println(commandUsageInfo);
            return;
        }

        if (argList != null && argList.size() > 1) {
            throw LauncherUtils.createUsageExceptionWithHelp("too many arguments");
        }

        
        Path sourceRootPath = Paths.get(System.getProperty(USER_DIR));
        if (nativeBinary) {
            genNativeBinary(sourceRootPath, argList);
        } else if (argList == null || argList.size() == 0) {
            
            BuilderUtils.compileWithTestsAndWrite(sourceRootPath, offline, lockEnabled, skiptests, experimentalFlag,
                    siddhiRuntimeFlag);
        } else {
            
            String targetFileName;
            String pkgName = argList.get(0);
            if (pkgName.endsWith("/")) {
                pkgName = pkgName.substring(0, pkgName.length() - 1);
            }

            Path sourcePath = Paths.get(pkgName);

            
            pkgName = sourcePath.normalize().toString();

            if (outputFileName != null && !outputFileName.isEmpty()) {
                targetFileName = outputFileName;
            } else {
                targetFileName = pkgName;
            }

            Path resolvedFullPath = sourceRootPath.resolve(sourcePath);
            
            if (Files.isRegularFile(resolvedFullPath) &&
                    sourcePath.toString().endsWith(BLangConstants.BLANG_SRC_FILE_SUFFIX) &&
                    !RepoUtils.hasProjectRepo(sourceRootPath)) {
                
                
                
                
                
                targetFileName = getTargetFileName(Paths.get(targetFileName));

                
                Path parent = resolvedFullPath.getParent();
                sourceRootPath = parent != null ? parent : sourceRootPath;

                
                Path resolvedFileName = resolvedFullPath.getFileName();
                pkgName = resolvedFileName != null ? resolvedFileName.toString() : pkgName;

            } else if (Files.isDirectory(sourceRootPath)) { 
                
                if (Files.isDirectory(resolvedFullPath) && !RepoUtils.hasProjectRepo(sourceRootPath)) {
                    throw LauncherUtils.createLauncherException("you are trying to build a module that is not inside " +
                            "a project. Run `ballerina init` from " + sourceRootPath + " to initialize it as a " +
                            "project and then build the module.");
                }
                if (Files.isRegularFile(resolvedFullPath) && !sourcePath.toString().endsWith(BLANG_SRC_FILE_SUFFIX)) {
                    throw LauncherUtils.createLauncherException("only modules and " + BLANG_SRC_FILE_SUFFIX + " " +
                                                                "files can be used with the 'ballerina build' " +
                                                                        "command.");
                }

                if (Files.exists(resolvedFullPath)) {
                    if (Files.isRegularFile(resolvedFullPath) && !sourcePath.toString()
                                                                            .endsWith(BLANG_SRC_FILE_SUFFIX)) {
                        throw LauncherUtils.createLauncherException("only modules and " + BLANG_SRC_FILE_SUFFIX + " " +
                                                                    "files can be used with the 'ballerina build' " +
                                                                            "command.");
                    }
                } else {
                    throw LauncherUtils.createLauncherException("ballerina source does not exist '" + sourcePath + "'");
                }
                
                
                
                Path parentPath = sourcePath.getParent();
                if (Files.isRegularFile(resolvedFullPath) && sourcePath.toString().endsWith(BLANG_SRC_FILE_SUFFIX) &&
                        parentPath != null) {
                    throw LauncherUtils.createLauncherException("you are trying to build a ballerina file inside a " +
                                                                        "module within a project. Try running " +
                                                                        "'ballerina build <module-name>'");
                }
            } else {
                
                throw LauncherUtils.createLauncherException("invalid ballerina source path, it should either be a " +
                                                                    "directory or a file  with a \'"
                                                            + BLangConstants.BLANG_SRC_FILE_SUFFIX + "\' extension");
            }

            
            
            LauncherUtils.loadConfigurations(sourceRootPath, configFilePath);

            if (jvmTarget || JVM_TARGET.equals(System.getProperty(BALLERINA_TARGET))) {
                BuilderUtils.compileAndWriteJar(sourceRootPath, pkgName, targetFileName, buildCompiledPkg,
                        offline, lockEnabled, skiptests, experimentalFlag, dumpBIR);
            } else {
                BuilderUtils.compileWithTestsAndWrite(sourceRootPath, pkgName, targetFileName, buildCompiledPkg,
                        offline, lockEnabled, skiptests, experimentalFlag, siddhiRuntimeFlag);
            }
        }
        Runtime.getRuntime().exit(0);
    }

Line commented on: if (jvmTarget || JVM_TARGET.equals(System.getProperty(BALLERINA_TARGET))) {

Revised code:
public void execute() {
        if (helpFlag) {
            String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(BUILD_COMMAND);
            outStream.println(commandUsageInfo);
            return;
        }

        if (argList != null && argList.size() > 1) {
            throw LauncherUtils.createUsageExceptionWithHelp("too many arguments");
        }

        
        Path sourceRootPath = Paths.get(System.getProperty(USER_DIR));
        if (nativeBinary) {
            genNativeBinary(sourceRootPath, argList);
        } else if (argList == null || argList.size() == 0) {
            
            BuilderUtils.compileWithTestsAndWrite(sourceRootPath, offline, lockEnabled, skiptests, experimentalFlag,
                    siddhiRuntimeFlag);
        } else {
            
            String targetFileName;
            String pkgName = argList.get(0);
            if (pkgName.endsWith("/")) {
                pkgName = pkgName.substring(0, pkgName.length() - 1);
            }

            Path sourcePath = Paths.get(pkgName);

            
            pkgName = sourcePath.normalize().toString();

            if (outputFileName != null && !outputFileName.isEmpty()) {
                targetFileName = outputFileName;
            } else {
                targetFileName = pkgName;
            }

            Path resolvedFullPath = sourceRootPath.resolve(sourcePath);
            
            if (Files.isRegularFile(resolvedFullPath) &&
                    sourcePath.toString().endsWith(BLangConstants.BLANG_SRC_FILE_SUFFIX) &&
                    !RepoUtils.hasProjectRepo(sourceRootPath)) {
                
                
                
                
                
                targetFileName = getTargetFileName(Paths.get(targetFileName));

                
                Path parent = resolvedFullPath.getParent();
                sourceRootPath = parent != null ? parent : sourceRootPath;

                
                Path resolvedFileName = resolvedFullPath.getFileName();
                pkgName = resolvedFileName != null ? resolvedFileName.toString() : pkgName;

            } else if (Files.isDirectory(sourceRootPath)) { 
                
                if (Files.isDirectory(resolvedFullPath) && !RepoUtils.hasProjectRepo(sourceRootPath)) {
                    throw LauncherUtils.createLauncherException("you are trying to build a module that is not inside " +
                            "a project. Run `ballerina init` from " + sourceRootPath + " to initialize it as a " +
                            "project and then build the module.");
                }
                if (Files.isRegularFile(resolvedFullPath) && !sourcePath.toString().endsWith(BLANG_SRC_FILE_SUFFIX)) {
                    throw LauncherUtils.createLauncherException("only modules and " + BLANG_SRC_FILE_SUFFIX + " " +
                                                                "files can be used with the 'ballerina build' " +
                                                                        "command.");
                }

                if (Files.exists(resolvedFullPath)) {
                    if (Files.isRegularFile(resolvedFullPath) && !sourcePath.toString()
                                                                            .endsWith(BLANG_SRC_FILE_SUFFIX)) {
                        throw LauncherUtils.createLauncherException("only modules and " + BLANG_SRC_FILE_SUFFIX + " " +
                                                                    "files can be used with the 'ballerina build' " +
                                                                            "command.");
                    }
                } else {
                    throw LauncherUtils.createLauncherException("ballerina source does not exist '" + sourcePath + "'");
                }
                
                
                
                Path parentPath = sourcePath.getParent();
                if (Files.isRegularFile(resolvedFullPath) && sourcePath.toString().endsWith(BLANG_SRC_FILE_SUFFIX) &&
                        parentPath != null) {
                    throw LauncherUtils.createLauncherException("you are trying to build a ballerina file inside a " +
                                                                        "module within a project. Try running " +
                                                                        "'ballerina build <module-name>'");
                }
            } else {
                
                throw LauncherUtils.createLauncherException("invalid ballerina source path, it should either be a " +
                                                                    "directory or a file  with a \'"
                                                            + BLangConstants.BLANG_SRC_FILE_SUFFIX + "\' extension");
            }

            
            
            LauncherUtils.loadConfigurations(sourceRootPath, configFilePath);

            if (jvmTarget || JVM_TARGET.equals(System.getProperty(BALLERINA_TARGET))) {
                BuilderUtils.compileAndWriteJar(sourceRootPath, pkgName, targetFileName, buildCompiledPkg,
                        offline, lockEnabled, skiptests, experimentalFlag, dumpBIR);
            } else {
                BuilderUtils.compileWithTestsAndWrite(sourceRootPath, pkgName, targetFileName, buildCompiledPkg,
                        offline, lockEnabled, skiptests, experimentalFlag, siddhiRuntimeFlag);
            }
        }
        Runtime.getRuntime().exit(0);
    }