Gradle
- Maven仓库配置
-
repositories { mavenLocal() // 已内置;但断网时还需要显式声明在第一行。 maven { // 公开访问 url = uri("https://staticfiles.openle.com/.well-known/maven/our/maven-public-snapshot/") //url "https://asia-northeast1-maven.pkg.dev/project-000000/maven-public-snapshot/" // 若改为GAR插件识别的 artifactregistry://... 协议,可从GCE环境获取和配置Token content { includeGroup("com.openle.module") } // 可配多次 - includeGroup } maven { // 私有仓库 url = uri("https://staticfiles.openle.com/.well-known/maven/our/maven-private-snapshot/") content { includeGroup("com.openle.our") } // 不写 authentication{} 则默认 BasicAuthentication;未响应401则应显式配置。 authentication { create<BasicAuthentication>("basic") } name = "OurMavenRepo" //credentials { username = "user"; password = "pwd" } credentials(PasswordCredentials::class) /* Windows环境变量区分大小写: SETX ORG_GRADLE_PROJECT_OurMavenRepoUsername "user" /M SETX ORG_GRADLE_PROJECT_OurMavenRepoPassword "pwd" /M 或 ./gradle -POurMavenRepoUsername=user -POurMavenRepoPassword=pwd */ } //google() // 仅用于Android项目 mavenCentral() } // 以下配置还未改为kts写法: apply plugin: "java" // gradle内置了该plugin,无需写入plugins块儿。 apply plugin: "maven-publish" // 同上。 publishing { repositories { maven { // 解决withJavadocJar()上传超时:systemProp.org.gradle.internal.http.socketTimeout=300000 url "https://asia-northeast1-maven.pkg.dev/project-000000/maven-public-snapshot/" credentials { // 重点:若配置了credentials.username则可去掉插件,将协议改为“https://...”即可。 // 编码key.json内容为base64后username改用_json_key_base64 username = "_json_key" password = file('../../../../docs/cloud/project-000000-8ad030ce3d3e.json').text } authentication { basic(BasicAuthentication) } } } publications { mainRelease(MavenPublication) { from(components.java) } } }
- 打开程序或命令行
-
注意 - NetBeans默认输出终端为cmd,若想回显powershell则要用/c启动。 tasks.register<Exec>("quarkusRunNew") { group="My" // environment=整体替换 var username = providers.environmentVariable("ORG_GRADLE_PROJECT_OurMavenRepoUsername").getOrNull(); var password = providers.environmentVariable("ORG_GRADLE_PROJECT_OurMavenRepoPassword").getOrNull(); var tmpdir = providers.systemProperty("java.io.tmpdir").getOrNull(); // 避免回落到"C:\Windows\",以免类库无权写入。 environment=mapOf("JAVA_HOME" to System.getenv("JAVA_HOME"),"tmp" to tmpdir, "SystemDrive" to System.getenv("SystemDrive"), // [可选]不写会在当前项目下生成 %SystemDrive% 目录 "ORG_GRADLE_PROJECT_OurMavenRepoPassword" to password ,"ORG_GRADLE_PROJECT_OurMavenRepoUsername" to username) for (key in environment.keys) { println(key +" - "+environment[key]) } //commandLine("cmd","/c","start","powershell","-NoExit","-command","ls env:") commandLine("cmd","/c","start","powershell","-NoExit","-command","../gradlew -x check --info quarkusRun") }
- war打包时加入文件
-
tasks.war { webInf { from("src/main/resources/ibm-web-bnd.xml"); into("/WEB-INF/") } }
Shell
- Shell备份Docker业务数据
-
sudo rm /etc/systemd/system/our-back-up-db.service sudo vim.tiny /etc/systemd/system/our-back-up-db.service [Unit] Description=our-back-up-db [Service] Type=oneshot # 注意 - 大于符号 > 必须写在'单引号'内!或用x.sh脚本文件。 ExecStartPre=/bin/sh -c '/usr/bin/docker exec our-mariadb sh -c \'exec mariadb-dump --databases oauth other -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction\' | gzip > /tmp/our-back-up-db.sql.gz' # 注意 - $(date +%T)中%字符后的字母前必须用+加号隔开下。 ExecStart=/bin/sh -c 'curl -X POST https://domain/back-up -F "file=@/tmp/our-back-up-db.sql.gz; type=application/gzip; filename=$(TZ='Asia/Shanghai' date +%+F_%+T).sql.gz" -F subDirName=databases' [Install] WantedBy=multi-user.target sudo systemctl daemon-reload [MariaDB启动较慢,无需开机启动,仅用timer调] sudo systemctl enable 【our-back-up-db.service】 [执行备份测试下] sudo systemctl start our-back-up-db.service sudo systemctl status our-back-up-db.service sudo vim.tiny /etc/systemd/system/our-back-up-weekly.timer [Unit] Description=our-back-up-weekly [Timer] #OnCalendar=minutely OnCalendar=weekly Unit=our-back-up-db.service [Install] WantedBy=timers.target sudo systemctl start our-back-up-weekly.timer 开机启动 sudo systemctl enable our-back-up-weekly.timer sudo systemctl status our-back-up-weekly.timer 暂停 sudo systemctl stop our-back-up-weekly.timer 永停 sudo systemctl disable our-back-up-weekly.timer 列出 systemctl list-timers