当前位置: 首页 > java >正文

使用gitea发布软件包

1、新建hello工程


(1)HelloApplication.java

package cn.ac.trimps.sv;import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class HelloApplication implements CommandLineRunner {public static void main(String[] args) {SpringApplication.run(HelloApplication.class, args);}@Overridepublic void run(String... arg0) throws Exception {}}

(2)EnableHello.java

package cn.ac.trimps.sv.config;import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;import org.springframework.context.annotation.Import;@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Import({HelloConfig.class})
public @interface EnableHello {}

(3)HelloConfig.java

package cn.ac.trimps.sv.config;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;@Configuration
@ComponentScan("cn.ac.trimps.sv.**")
public class HelloConfig {}

(4)HelloController.java

package cn.ac.trimps.sv.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;import cn.ac.trimps.sv.service.HelloService;@RestController
@RequestMapping("hello")
public class HelloController {@AutowiredHelloService helloService;@RequestMapping(value = "", method = RequestMethod.GET)public String helloWorld() {return helloService.helloWorld();}}

(5)HelloService.java

package cn.ac.trimps.sv.service;import org.springframework.stereotype.Service;import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;@Slf4j
@Service
public class HelloService {public String helloWorld() {String str = StrUtil.format("{} {}.", "hello", "world");log.info("{}", str);return str;}}

(6)application.properties


logging.config=classpath:logback-plus.xmlserver.port=1400

(7)logback-plus.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration><include resource="org/springframework/boot/logging/logback/defaults.xml" /><appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset></encoder><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO</level></filter></appender><appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><file>/home/logs/hello/stdout.log</file><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- daily rollover 保存历史记录到这个文件夹一日起为后缀 --><fileNamePattern>/home/logs/hello/stdout.log.%d{yyyy-MM-dd}-%i.log</fileNamePattern><!-- keep 30 days' worth of history --><maxHistory>30</maxHistory><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>INFO</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"><file>/home/logs/hello/stderr.log</file><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- daily rollover 保存历史记录到这个文件夹一日起为后缀 --><fileNamePattern>/home/logs/hello/stderr.log.%d{yyyy-MM-dd}-%i.log</fileNamePattern><!-- keep 30 days' worth of history --><maxHistory>30</maxHistory><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>ERROR</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><root level="INFO"><appender-ref ref="CONSOLE"></appender-ref><appender-ref ref="FILE"></appender-ref><appender-ref ref="FILE_ERROR"></appender-ref></root>
</configuration>

(8)build.gradle

plugins {id 'org.springframework.boot' version '2.7.18'id 'io.spring.dependency-management' version '1.0.15.RELEASE'id 'java'id 'eclipse'id 'maven-publish'
}group = 'cn.ac.trimps.sv'
version = '0.0.1'
sourceCompatibility = 1.8repositories {maven {url 'https://maven.aliyun.com/repository/public'}mavenCentral()
}jar {// 移除分类器(默认是 'plain')archiveClassifier = ''
}bootJar {// 自定义文件名称archiveFileName = "${project.name}-${project.version}.jar"launchScript()
}publishing {publications {mavenJava(MavenPublication) {// 发布普通Jarfrom components.java}}repositories {maven {name = 'Gitea'url = uri('http://127.0.0.1:3004/api/packages/huangwending/maven')credentials(HttpHeaderCredentials) {// 令牌名称name = 'Authorization'// 令牌value = 'token 033b2cfce7541387c1e272be45275cd926dc922c'}authentication {header(HttpHeaderAuthentication)}}}
}dependencies {implementation 'org.springframework.boot:spring-boot-starter-web'implementation 'cn.hutool:hutool-all:5.8.37'compileOnly 'org.projectlombok:lombok'developmentOnly 'org.springframework.boot:spring-boot-devtools'annotationProcessor 'org.projectlombok:lombok'testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

2、发布hello工程jar包至本地gitea仓库

命令:gradle clean publishAllPublicationsToGiteaRepository --info

PS G:\workspace\study\hello> gradle clean publishAllPublicationsToGiteaRepository --info
Initialized native services in: E:\.gradle-6.8.3\native
The client will now receive all logging from the daemon (pid: 22512). The daemon log file: E:\.gradle-6.8.3\daemon\6.8.3\daemon-22512.out.log
Starting 30th build in daemon [uptime: 3 hrs 5 mins 0.129 secs, performance: 99%, GC rate: 0.00/s, heap usage: 8% of 341.5 MiB, non-heap usage: 31% of 256 MiB]
Using 8 worker leases.
Watching the file system is disabled
Starting Build
Settings evaluated using settings file 'G:\workspace\study\hello\settings.gradle'.
Projects loaded. Root project using build file 'G:\workspace\study\hello\build.gradle'.
Included projects: [root project 'hello']> Configure project :
Evaluating root project 'hello' using build file 'G:\workspace\study\hello\build.gradle'.
Compiling build file 'G:\workspace\study\hello\build.gradle' using SubsetScriptTransformer.
Applying dependency management to configuration 'bootArchives' in project 'hello'
Applying dependency management to configuration 'archives' in project 'hello'
Applying dependency management to configuration 'default' in project 'hello'
Applying dependency management to configuration 'compile' in project 'hello'
Applying dependency management to configuration 'implementation' in project 'hello'
Applying dependency management to configuration 'runtime' in project 'hello'
Applying dependency management to configuration 'compileOnly' in project 'hello'
Applying dependency management to configuration 'compileClasspath' in project 'hello'
Applying dependency management to configuration 'annotationProcessor' in project 'hello'
Applying dependency management to configuration 'runtimeOnly' in project 'hello'
Applying dependency management to configuration 'runtimeClasspath' in project 'hello'
Applying dependency management to configuration 'testCompile' in project 'hello'
Applying dependency management to configuration 'testImplementation' in project 'hello'
Applying dependency management to configuration 'testRuntime' in project 'hello'
Applying dependency management to configuration 'testCompileOnly' in project 'hello'
Applying dependency management to configuration 'testCompileClasspath' in project 'hello'
Applying dependency management to configuration 'testAnnotationProcessor' in project 'hello'
Applying dependency management to configuration 'testRuntimeOnly' in project 'hello'
Applying dependency management to configuration 'testRuntimeClasspath' in project 'hello'
Applying dependency management to configuration 'apiElements' in project 'hello'
Applying dependency management to configuration 'runtimeElements' in project 'hello'
Applying dependency management to configuration 'developmentOnly' in project 'hello'
Applying dependency management to configuration 'productionRuntimeClasspath' in project 'hello'
Compiling build file 'G:\workspace\study\hello\build.gradle' using BuildScriptTransformer.
All projects evaluated.
Selected primary task 'clean' from project :
Selected primary task 'publishAllPublicationsToGiteaRepository' from project :
Tasks to be executed: [task ':clean', task ':compileJava', task ':processResources', task ':classes', task ':jar', task ':generateMetadataFileForMavenJavaPublication', task ':generatePomFileForMavenJavaPublication', task ':publishMavenJavaPublicationToGiteaRepository', task ':publishAllPublicationsToGiteaRepository']
Tasks that were excluded: []
:clean (Thread[Execution worker for ':',5,main]) started.> Task :clean UP-TO-DATE
Caching disabled for task ':clean' because:Build cache is disabled
Task ':clean' is not up-to-date because:Task has not declared any outputs despite executing actions.
:clean (Thread[Execution worker for ':',5,main]) completed. Took 0.022 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.> Task :compileJava
Resolving global dependency management for project 'hello'
Excluding []
Excluding []
Caching disabled for task ':compileJava' because:Build cache is disabled
Task ':compileJava' is not up-to-date because:No history is available.
The input changes require a full rebuild for incremental task ':compileJava'.
Invalidating in-memory cache of G:\workspace\study\hello\.gradle\6.8.3\javaCompile\classAnalysis.bin
Invalidating in-memory cache of G:\workspace\study\hello\.gradle\6.8.3\javaCompile\jarAnalysis.bin
Invalidating in-memory cache of G:\workspace\study\hello\.gradle\6.8.3\javaCompile\taskHistory.bin
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
Compiling with JDK Java compiler API.
Created classpath snapshot for incremental compilation in 0.066 secs. 1 duplicate classes found in classpath (see all with --debug).
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 4.609 secs.
:processResources (Thread[Execution worker for ':',5,main]) started.> Task :processResources
Caching disabled for task ':processResources' because:Build cache is disabled
Task ':processResources' is not up-to-date because:No history is available.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.108 secs.
:classes (Thread[Execution worker for ':',5,main]) started.> Task :classes
Skipping task ':classes' as it has no actions.
:classes (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:jar (Thread[Execution worker for ':',5,main]) started.> Task :jar
Caching disabled for task ':jar' because:Build cache is disabled
Task ':jar' is not up-to-date because:No history is available.
:jar (Thread[Execution worker for ':',5,main]) completed. Took 0.127 secs.
:generateMetadataFileForMavenJavaPublication (Thread[Execution worker for ':',5,main]) started.> Task :generateMetadataFileForMavenJavaPublication
Caching disabled for task ':generateMetadataFileForMavenJavaPublication' because:Build cache is disabled
Task ':generateMetadataFileForMavenJavaPublication' is not up-to-date because:Task.upToDateWhen is false.
:generateMetadataFileForMavenJavaPublication (Thread[Execution worker for ':',5,main]) completed. Took 0.116 secs.
:generatePomFileForMavenJavaPublication (Thread[Execution worker for ':',5,main]) started.> Task :generatePomFileForMavenJavaPublication
Caching disabled for task ':generatePomFileForMavenJavaPublication' because:Build cache is disabled
Task ':generatePomFileForMavenJavaPublication' is not up-to-date because:Task.upToDateWhen is false.
:generatePomFileForMavenJavaPublication (Thread[Execution worker for ':',5,main]) completed. Took 0.358 secs.
:publishMavenJavaPublicationToGiteaRepository (Thread[Execution worker for ':',5,main]) started.> Task :publishMavenJavaPublicationToGiteaRepository
Caching disabled for task ':publishMavenJavaPublicationToGiteaRepository' because:Build cache is disabled
Task ':publishMavenJavaPublicationToGiteaRepository' is not up-to-date because:Task has not declared any outputs despite executing actions.
Publishing to repository 'Gitea' (http://127.0.0.1:3004/api/packages/huangwending/maven)
Uploading hello-0.0.1.jar to /api/packages/huangwending/maven/cn/ac/trimps/sv/hello/0.0.1/hello-0.0.1.jar
Uploading hello-0.0.1.pom to /api/packages/huangwending/maven/cn/ac/trimps/sv/hello/0.0.1/hello-0.0.1.pom
Uploading hello-0.0.1.module to /api/packages/huangwending/maven/cn/ac/trimps/sv/hello/0.0.1/hello-0.0.1.module
Uploading maven-metadata.xml to /api/packages/huangwending/maven/cn/ac/trimps/sv/hello/maven-metadata.xml
:publishMavenJavaPublicationToGiteaRepository (Thread[Execution worker for ':',5,main]) completed. Took 1.793 secs.
:publishAllPublicationsToGiteaRepository (Thread[Execution worker for ':',5,main]) started.> Task :publishAllPublicationsToGiteaRepository
Skipping task ':publishAllPublicationsToGiteaRepository' as it has no actions.
:publishAllPublicationsToGiteaRepository (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.BUILD SUCCESSFUL in 14s
7 actionable tasks: 6 executed, 1 up-to-date
PS G:\workspace\study\hello>


3、新建test工程,并引用发布的依赖

(1)TestApplication.java

package cn.ac.trimps.sv;import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;import cn.ac.trimps.sv.config.EnableHello;@EnableHello
@Configuration
@SpringBootApplication
public class TestApplication implements CommandLineRunner {public static void main(String[] args) {SpringApplication.run(TestApplication.class, args);}@Overridepublic void run(String... arg0) throws Exception {}}

(2)TestController.java

package cn.ac.trimps.sv.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;import cn.ac.trimps.sv.service.HelloService;@RestController
@RequestMapping("test")
public class TestController {@AutowiredHelloService helloService;@RequestMapping(value = "f1", method = RequestMethod.GET)public String f1() {return helloService.helloWorld();}}

(3)application.properties


logging.config=classpath:logback-plus.xmlserver.port=1401

(4)logback-plus.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration><include resource="org/springframework/boot/logging/logback/defaults.xml" /><appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset></encoder><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO</level></filter></appender><appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><file>/home/logs/test/stdout.log</file><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- daily rollover 保存历史记录到这个文件夹一日起为后缀 --><fileNamePattern>/home/logs/test/stdout.log.%d{yyyy-MM-dd}-%i.log</fileNamePattern><!-- keep 30 days' worth of history --><maxHistory>30</maxHistory><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>INFO</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"><file>/home/logs/test/stderr.log</file><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- daily rollover 保存历史记录到这个文件夹一日起为后缀 --><fileNamePattern>/home/logs/test/stderr.log.%d{yyyy-MM-dd}-%i.log</fileNamePattern><!-- keep 30 days' worth of history --><maxHistory>30</maxHistory><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg %n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>ERROR</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><root level="INFO"><appender-ref ref="CONSOLE"></appender-ref><appender-ref ref="FILE"></appender-ref><appender-ref ref="FILE_ERROR"></appender-ref></root>
</configuration>

(5)build.gradle

plugins {id 'org.springframework.boot' version '2.7.18'id 'io.spring.dependency-management' version '1.0.15.RELEASE'id 'java'id 'eclipse'
}group = 'cn.ac.trimps.sv'
version = '0.0.1'
sourceCompatibility = 1.8repositories {maven {url 'http://127.0.0.1:3004/api/packages/huangwending/maven'allowInsecureProtocol = true}maven {url 'https://maven.aliyun.com/repository/public'}mavenCentral()
}bootJar {launchScript()
}dependencies {implementation 'org.springframework.boot:spring-boot-starter-web'implementation 'cn.ac.trimps.sv:hello:0.0.1'compileOnly 'org.projectlombok:lombok'developmentOnly 'org.springframework.boot:spring-boot-devtools'annotationProcessor 'org.projectlombok:lombok'testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

4、运行test工程,使用postman测试接口

http://www.xdnf.cn/news/3266.html

相关文章:

  • 学习路之windows --设置定时任务:每1个小时桌面弹个提示 “起身活动一下”
  • 目标检测YOLO实战应用案例100讲-基于多级特征融合的小目标深度检测网络
  • SpringClode
  • JavaScript加密库crypto-js
  • Redis集群搭建(哨兵模式+一主两从)
  • 蓝桥杯Python(B)省赛回忆
  • HTTP 503(Service Unavailable)
  • 在线服务器网站具体是指什么?
  • 10.idea中创建springboot项目_jdk17
  • 疾风气象大模型:实现太阳辐照度数据全球可视化的创新方案
  • WebSocket与Socket、TCP、HTTP的关系及区别
  • 文章记单词 | 第52篇(六级)
  • OpenCL 能取代 CUDA 吗?
  • 综合练习二
  • PCB设计实战技巧宝典:从库管理到布线优化的全流程解析
  • 「Mac畅玩AIGC与多模态09」开发篇05 - 使用自定义天气查询插件开发智能体应用
  • 数据库设计理论:从需求分析到实现的全流程解析
  • BT138-ASEMI无人机专用功率器件BT138
  • [原创](现代Delphi 12指南):[macOS 64bit App开发]: [1]如何使用原生NSAlert消息框 (runModal模式)
  • 从Oculus到Meta:Facebook实现元宇宙的硬件策略
  • 第十六届蓝桥杯 2025 C/C++组 数列差分
  • 氢混合气配气系统在传感器检测中的重要应用
  • 海外社交软件开发实战:从架构设计到合规落地的技术解析
  • 健达智能 盘古信息IMS项目启动:携手开启数字化转型新篇章
  • DC-DC常见应用问题解疑
  • 爬虫逆向思维
  • 深入理解 C++11 delete 关键字:禁用函数的艺术
  • CMU-15445(2)——PROJECT#0-C++PRIMER
  • [Java入门]抽象类和接口
  • Vue3源码学习3-结合vitetest来实现mini-vue